Example usage for org.jfree.chart.axis DateAxis setUpperBound

List of usage examples for org.jfree.chart.axis DateAxis setUpperBound

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateAxis setUpperBound.

Prototype

public void setUpperBound(double max) 

Source Link

Document

Sets the upper bound for the axis range, and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * some jFreeChart Axis settings for TimeValueDiagram
 * @param plot            jFreeChart plot instance
 * @param rangeAxisLabel   Label of rangeAxis
 *//*from  w  ww  .  j  av a  2 s  . c  o  m*/
private void buildTimeValueDiagramAxisFormat(XYPlot plot, String rangeAxisLabel) {
    System.out.println("StatisticGrafic.buildTimeValueDiagramAxisFormat");
    ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis();
    double a = 0.1 * Math.max(Math.abs(statistic.getValueLow()), Math.abs(statistic.getValueHigh()));
    rangeAxis.setLowerBound(statistic.getValueLow() - a);
    rangeAxis.setUpperBound(statistic.getValueHigh() + a);
    rangeAxis.setLabel(rangeAxisLabel);
    rangeAxis.setLabelFont(FONT_DEFAULT);

    DateAxis dateAxis = new DateAxis();
    DateAxis[] domainAxisArray = new DateAxis[1];
    domainAxisArray[0] = dateAxis;
    plot.setDomainAxes(domainAxisArray);

    dateAxis.setLowerBound(statistic.getTimeLow());
    dateAxis.setUpperBound(statistic.getTimeHigh());

    long diff = statistic.getTimeHigh() - statistic.getTimeLow();
    String format, unit;
    if (diff > 24 * 60 * 60 * 1000) {
        format = "d.MM.yyyy";
        unit = "[day]";
    } else if (diff > 60 * 60 * 1000) {
        format = "H:mm";
        unit = "[h]";
    } else if (diff > 60 * 1000) {
        format = "m:ss";
        unit = "[min]";
    } else if (diff > 1000) {
        format = "s.S";
        unit = "[sec]";
    } else {
        format = "S";
        unit = "[millisec]";
    }
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    dateAxis.setDateFormatOverride(sdf);
    SimpleDateFormat sdf1 = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS");
    String von = sdf1.format(dateAxis.getMinimumDate());
    String bis = sdf1.format(dateAxis.getMaximumDate());
    dateAxis.setLabel(von + "    Time " + unit + "   " + bis);
    dateAxis.setLabelFont(FONT_DEFAULT);

}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private void setDateAxisStyles(DateAxis axis, UIAxis comp) {
    UIDataSeries data = ((UIChart) comp.getParent()).getDataSeries();
    if (!(data instanceof UITimeSeries))
        return;//  www .  j  a  v  a2s  . c o  m
    UITimeSeries ts = (UITimeSeries) data;

    axis.setInverted(comp.isInverted());

    Object lowerBound = comp.getLowerBound();
    Object upperBound = comp.getUpperBound();
    Double lowerMargin = comp.getLowerMargin();
    Double upperMargin = comp.getUpperMargin();

    if (lowerBound != null)
        axis.setLowerBound(getTimePeriodValue(ts, lowerBound));
    if (upperBound != null)
        axis.setUpperBound(getTimePeriodValue(ts, upperBound));
    if (lowerMargin != null)
        axis.setLowerMargin(lowerMargin);
    if (upperMargin != null)
        axis.setUpperMargin(upperMargin);

    Double tickStep = comp.getTickStep();
    String tickFormat = comp.getTickLabelFormat();
    int dateTickUnit = 0;
    int dateTickStep = 0;

    if (tickStep != null) {
        dateTickStep = tickStep.intValue();

        TimePeriodType tp = comp.getTickUnit();
        if (tp == null) {
            tp = ts.getTimePeriod();
        }
        switch (tp) {
        case Year:
            dateTickUnit = DateTickUnit.YEAR;
            break;
        case Quarter:
            dateTickUnit = DateTickUnit.MONTH;
            dateTickStep *= 4;
            break;
        case Month:
            dateTickUnit = DateTickUnit.MONTH;
            break;
        case Week:
            dateTickUnit = DateTickUnit.DAY;
            dateTickStep *= 7;
            break;
        case Day:
            dateTickUnit = DateTickUnit.DAY;
            break;
        case Hour:
            dateTickUnit = DateTickUnit.HOUR;
            break;
        case Minute:
            dateTickUnit = DateTickUnit.MINUTE;
            break;
        case Second:
            dateTickUnit = DateTickUnit.SECOND;
            break;
        case Millisecond:
            dateTickUnit = DateTickUnit.MILLISECOND;
            break;
        default:
            throw new AssertionError();
        }
    }

    if ((tickStep != null && tickStep > 0) || tickFormat != null) {
        if (tickFormat == null) {
            axis.setTickUnit(new DateTickUnit(dateTickUnit, dateTickStep));
        } else if (tickStep == null) {
            DateFormat format = new SimpleDateFormat(tickFormat);
            axis.setDateFormatOverride(format);
        } else {
            DateFormat format = new SimpleDateFormat(tickFormat);
            axis.setTickUnit(new DateTickUnit(dateTickUnit, dateTickStep, format));
        }
    }
}