Example usage for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero

List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero.

Prototype

public void setAutoRangeIncludesZero(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.

Usage

From source file:diet.gridr.g5k.gui.GanttChart.java

/**
 * Method creating the chart//from ww  w.jav  a  2 s.co  m
 *
 * @param dataset dataset containing the data for the chart
 * @return a chart
 */
private JFreeChart createChart(XYZDataset dataset) {
    DateAxis xAxis = new DateAxis("Date");
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setDateFormatOverride(new SimpleDateFormat(durationsFormatterArray[this.visualizationDuration]));
    xAxis.setRange(Calendar.getInstance().getTime(),
            new Date(System.currentTimeMillis() + HistoryUtil.durationsTimesArray[visualizationDuration]
                    - HistoryUtil.blockWidthsArray[visualizationDuration]));
    NumberAxis yAxis = new NumberAxis("Nodes");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(true);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setRange(1, numberOfNodes);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer renderer = new XYBlockRenderer();
    LookupPaintScale paintScale = new LookupPaintScale();
    for (int i = 0; i < jobsList.get(visualizationDuration).size(); i++) {
        // String jobId = jobsList.get(visualizationDuration).get(i).getId().substring(0,jobsList.get(visualizationDuration).get(i).getId().indexOf("."));
        String jobId = jobsList.get(visualizationDuration).get(i).getParameterValue(GridJob.KEY_GRID_JOB_ID);
        int seed = Integer.parseInt(jobId);
        Random rng = new Random(seed);
        Color tempColor = Color.red;
        int red = tempColor.getRed();
        int green = tempColor.getGreen();
        int blue = tempColor.getBlue();
        int redRNG = rng.nextInt(255);
        int greenRNG = rng.nextInt(255);
        int blueRNG = rng.nextInt(255);
        if (red == redRNG && green == greenRNG && blue == blueRNG) {
            tempColor = new Color(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255));
        } else {
            tempColor = new Color(redRNG, greenRNG, blueRNG);
        }
        if (seed == 0)
            tempColor = Color.red;
        paintScale.add(new Double(i), tempColor);
    }
    renderer.setBlockWidth(HistoryUtil.blockWidthsArray[visualizationDuration]);
    renderer.setBlockAnchor(RectangleAnchor.TOP_LEFT);
    renderer.setPaintScale(paintScale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    JFreeChart chart = new JFreeChart("Gantt Chart activity for cluster " + siteName, plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    LoggingManager.log(Level.CONFIG, LoggingManager.RESOURCESTOOL, this.getClass().getName(), "createChart",
            "Chart created");
    return chart;
}

From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java

protected JFreeChart getFutureForecastChart(TSForecaster forecaster, List<List<NumericPrediction>> preds,
        List<String> targetNames, Instances history) {

    if (forecaster instanceof TSLagUser && history != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) {

            // fill in any missing time stamps only
            history = new Instances(history);
            history = weka.classifiers.timeseries.core.Utils.replaceMissing(history, null,
                    lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries());
        }/*from w w w  . j ava 2  s. c  o  m*/
    }

    // set up a collection of series
    XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection();

    if (history != null) {
        // add actual historical data values
        for (String targetName : targetNames) {
            XYIntervalSeries targetSeries = new XYIntervalSeries(targetName, false, false);
            xyDataset.addSeries(targetSeries);
        }
    }

    // add predicted series
    for (String targetName : targetNames) {
        XYIntervalSeries targetSeries = new XYIntervalSeries(targetName + "-predicted", false, false);
        xyDataset.addSeries(targetSeries);
    }

    ValueAxis timeAxis = null;
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false);
    int timeIndex = -1;
    boolean timeAxisIsDate = false;
    double artificialTimeStart = 0;
    double lastRealTimeValue = Utils.missingValue();
    if (forecaster instanceof TSLagUser && history != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) {
            String timeName = lagMaker.getTimeStampField();
            if (history.attribute(timeName).isDate()) {
                timeAxis = new DateAxis("");
                timeAxisIsDate = true;
                timeIndex = history.attribute(timeName).index();
            }
        } else {
            try {
                artificialTimeStart = (history != null) ? 1 : lagMaker.getArtificialTimeStartValue() + 1;
            } catch (Exception ex) {
            }
        }
    }

    if (timeAxis == null) {
        timeAxis = new NumberAxis("");
        ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false);
    }

    boolean hasConfidenceIntervals = false;

    // now populate the series
    if (history != null) {

        // do the actuals first
        for (int i = 0; i < history.numInstances(); i++) {
            Instance current = history.instance(i);

            for (String targetName : targetNames) {
                int dataIndex = history.attribute(targetName.trim()).index();

                if (dataIndex >= 0) {
                    XYIntervalSeries actualSeries = null;
                    int actualIndex = xyDataset.indexOf(targetName);
                    actualSeries = xyDataset.getSeries(actualIndex);
                    double x = Utils.missingValue();

                    if (timeAxisIsDate) {
                        x = current.value(timeIndex);
                        if (!Utils.isMissingValue(x)) {
                            lastRealTimeValue = x;
                        }
                    } else {
                        x = artificialTimeStart;
                    }

                    double y = Utils.missingValue();
                    y = current.value(dataIndex);

                    if (!Utils.isMissingValue(x) && !Utils.isMissingValue(y)) {
                        if (actualSeries != null) {
                            actualSeries.add(x, x, x, y, y, y);
                        }
                    }
                }
            }

            if (!timeAxisIsDate) {
                artificialTimeStart++;
            }
        }
    }

    // now do the futures
    List<String> forecasterTargets = AbstractForecaster.stringToList(forecaster.getFieldsToForecast());

    // loop over the steps
    for (int j = 0; j < preds.size(); j++) {
        List<NumericPrediction> predsForStepJ = preds.get(j);

        // advance the real time index (if appropriate)
        if (timeAxisIsDate) {
            lastRealTimeValue = ((TSLagUser) forecaster).getTSLagMaker()
                    .advanceSuppliedTimeValue(lastRealTimeValue);
        }
        for (String targetName : targetNames) {

            // look up this requested target in the list that the forecaster
            // has predicted
            int predIndex = forecasterTargets.indexOf(targetName.trim());
            if (predIndex >= 0) {
                NumericPrediction predsForTargetAtStepJ = predsForStepJ.get(predIndex);
                XYIntervalSeries predSeries = null;
                int datasetIndex = xyDataset.indexOf(targetName + "-predicted");
                predSeries = xyDataset.getSeries(datasetIndex);

                if (predSeries != null) {
                    double y = predsForTargetAtStepJ.predicted();
                    double x = Utils.missingValue();
                    double yHigh = y;
                    double yLow = y;
                    double[][] conf = predsForTargetAtStepJ.predictionIntervals();
                    if (conf.length > 0) {
                        yLow = conf[0][0];
                        yHigh = conf[0][1];
                        hasConfidenceIntervals = true;
                    }

                    if (!timeAxisIsDate) {
                        x = artificialTimeStart;
                    } else {
                        x = lastRealTimeValue;
                    }

                    if (!Utils.isMissingValue(x) && !Utils.isMissingValue(y)) {
                        predSeries.add(x, x, x, y, yLow, yHigh);
                    }
                }
            }
        }

        // advance the artificial time index (if appropriate)
        if (!timeAxisIsDate) {
            artificialTimeStart++;
        }
    }

    String title = "Future forecast for: ";
    for (String s : targetNames) {
        title += s + ",";
    }
    title = title.substring(0, title.lastIndexOf(","));

    /*
     * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec
     * + ")";
     */

    if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) {
        double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0;
        title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]";
    }

    XYErrorRenderer renderer = new XYErrorRenderer();

    // renderer.setShapesFilled(true);
    XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
    // renderer = (XYErrorRenderer)plot.getRenderer();
    if (history != null) {
        for (String targetName : targetNames) {
            XYIntervalSeries predSeries = null;
            int predIndex = xyDataset.indexOf(targetName + "-predicted");
            predSeries = xyDataset.getSeries(predIndex);

            XYIntervalSeries actualSeries = null;
            int actualIndex = xyDataset.indexOf(targetName);
            actualSeries = xyDataset.getSeries(actualIndex);

            if (actualSeries != null && predSeries != null) {
                // match the color of the actual series
                java.awt.Paint actualPaint = renderer.lookupSeriesPaint(actualIndex);
                renderer.setSeriesPaint(predIndex, actualPaint);

                // now set the line style to dashed
                BasicStroke dashed = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                        new float[] { 5.0f }, 0.0f);

                renderer.setSeriesStroke(predIndex, dashed);
            }
        }
    }

    renderer.setBaseLinesVisible(true);
    renderer.setDrawXError(false);
    renderer.setDrawYError(true);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(java.awt.Color.white);
    TextTitle chartTitle = chart.getTitle();
    String fontName = chartTitle.getFont().getFontName();
    java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12);
    chartTitle.setFont(newFont);

    return chart;
}

From source file:org.n52.server.io.render.DiagramRenderer.java

/**
 * <pre>// w ww  .  j  a  v a 2 s.c o m
 * dataset :=  associated to one range-axis;
 * corresponds to one observedProperty;
 * may contain multiple series;
 * series :=   corresponds to a time series for one foi
 * </pre>
 *
 * .
 *
 * @param entireCollMap
 *            the entire coll map
 * @param options
 *            the options
 * @param begin
 *            the begin
 * @param end
 *            the end
 * @param compress
 * @return the j free chart
 */
public JFreeChart renderChart(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options,
        Calendar begin, Calendar end, boolean compress) {

    DesignDescriptionList designDescriptions = buildUpDesignDescriptionList(options);

    /*** FIRST RUN ***/
    JFreeChart chart = initializeTimeSeriesChart();
    chart.setBackgroundPaint(Color.white);

    if (!this.isOverview) {
        chart.addSubtitle(new TextTitle(ConfigurationContext.COPYRIGHT, new Font(LABEL_FONT, Font.PLAIN, 9),
                Color.black, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM,
                new RectangleInsets(0, 0, 20, 20)));
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.setDomainGridlinesVisible(options.getGrid());
    plot.setRangeGridlinesVisible(options.getGrid());

    // add additional datasets:
    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setRange(begin.getTime(), end.getTime());
    dateAxis.setDateFormatOverride(new SimpleDateFormat());
    dateAxis.setTimeZone(end.getTimeZone());

    // add all axes
    String[] phenomenaIds = options.getAllPhenomenIds();
    // all the axis indices to map them later
    HashMap<String, Integer> axes = new HashMap<String, Integer>();
    for (int i = 0; i < phenomenaIds.length; i++) {
        axes.put(phenomenaIds[i], i);
        plot.setRangeAxis(i, new NumberAxis(phenomenaIds[i]));
    }

    // list range markers
    ArrayList<ValueMarker> referenceMarkers = new ArrayList<ValueMarker>();
    HashMap<String, double[]> referenceBounds = new HashMap<String, double[]>();

    // create all TS collections
    for (int i = 0; i < options.getProperties().size(); i++) {

        TimeseriesProperties prop = options.getProperties().get(i);

        String phenomenonId = prop.getPhenomenon();

        TimeSeriesCollection dataset = createDataset(entireCollMap, prop, phenomenonId, compress);
        dataset.setGroup(new DatasetGroup(prop.getTimeseriesId()));
        XYDataset additionalDataset = dataset;

        NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenomenonId));

        if (this.isOverview) {
            axe.setAutoRange(true);
            axe.setAutoRangeIncludesZero(false);
        } else if (prop.getAxisUpperBound() == prop.getAxisLowerBound() || prop.isAutoScale()) {
            if (prop.isZeroScaled()) {
                axe.setAutoRangeIncludesZero(true);
            } else {
                axe.setAutoRangeIncludesZero(false);
            }
        } else {
            if (prop.isZeroScaled()) {
                if (axe.getUpperBound() < prop.getAxisUpperBound()) {
                    axe.setUpperBound(prop.getAxisUpperBound());
                }
                if (axe.getLowerBound() > prop.getAxisLowerBound()) {
                    axe.setLowerBound(prop.getAxisLowerBound());
                }
            } else {
                axe.setRange(prop.getAxisLowerBound(), prop.getAxisUpperBound());
                axe.setAutoRangeIncludesZero(false);
            }
        }

        plot.setDataset(i, additionalDataset);
        plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId));

        // set bounds new for reference values
        if (!referenceBounds.containsKey(phenomenonId)) {
            double[] bounds = new double[] { axe.getLowerBound(), axe.getUpperBound() };
            referenceBounds.put(phenomenonId, bounds);
        } else {
            double[] bounds = referenceBounds.get(phenomenonId);
            if (bounds[0] >= axe.getLowerBound()) {
                bounds[0] = axe.getLowerBound();
            }
            if (bounds[1] <= axe.getUpperBound()) {
                bounds[1] = axe.getUpperBound();
            }
        }

        double[] bounds = referenceBounds.get(phenomenonId);
        for (String string : prop.getReferenceValues()) {
            if (prop.getRefValue(string).show()) {
                Double value = prop.getRefValue(string).getValue();
                if (value <= bounds[0]) {
                    bounds[0] = value;
                } else if (value >= bounds[1]) {
                    bounds[1] = value;
                }
            }
        }

        Axis axis = prop.getAxis();
        if (axis == null) {
            axis = new Axis(axe.getUpperBound(), axe.getLowerBound());
        } else if (prop.isAutoScale()) {
            axis.setLowerBound(axe.getLowerBound());
            axis.setUpperBound(axe.getUpperBound());
            axis.setMaxY(axis.getMaxY());
            axis.setMinY(axis.getMinY());
        }
        prop.setAxisData(axis);
        this.axisMapping.put(prop.getTimeseriesId(), axis);

        for (String string : prop.getReferenceValues()) {
            if (prop.getRefValue(string).show()) {
                referenceMarkers.add(new ValueMarker(prop.getRefValue(string).getValue(),
                        Color.decode(prop.getRefValue(string).getColor()),
                        new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)));
            }
        }

        plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId));
    }

    for (ValueMarker valueMarker : referenceMarkers) {
        plot.addRangeMarker(valueMarker);
    }

    // show actual time
    ValueMarker nowMarker = new ValueMarker(System.currentTimeMillis(), Color.orange,
            new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f));
    plot.addDomainMarker(nowMarker);

    if (!this.isOverview) {
        Iterator<Entry<String, double[]>> iterator = referenceBounds.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, double[]> boundsEntry = iterator.next();
            String phenId = boundsEntry.getKey();
            NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenId));
            axe.setAutoRange(true);
            // add a margin
            double marginOffset = (boundsEntry.getValue()[1] - boundsEntry.getValue()[0]) / 25;
            boundsEntry.getValue()[0] -= marginOffset;
            boundsEntry.getValue()[1] += marginOffset;
            axe.setRange(boundsEntry.getValue()[0], boundsEntry.getValue()[1]);
        }
    }

    /**** SECOND RUN ***/

    // set domain axis labels:
    plot.getDomainAxis().setLabelFont(label);
    plot.getDomainAxis().setLabelPaint(LABEL_COLOR);
    plot.getDomainAxis().setTickLabelFont(tickLabelDomain);
    plot.getDomainAxis().setTickLabelPaint(LABEL_COLOR);
    plot.getDomainAxis().setLabel(designDescriptions.getDomainAxisLabel());

    // define the design for each series:
    for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {
        TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(datasetIndex);

        for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) {

            String timeseriesId = (String) dataset.getSeries(seriesIndex).getKey();
            RenderingDesign dd = designDescriptions.get(timeseriesId);

            if (dd != null) {

                // LINESTYLE:
                String lineStyle = dd.getLineStyle();
                int width = dd.getLineWidth();
                if (this.isOverview) {
                    width = width / 2;
                    width = (width == 0) ? 1 : width;
                }
                // "1" is lineStyle "line"
                if (lineStyle.equalsIgnoreCase(LINE)) {
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, false);
                    ren.setStroke(new BasicStroke(width));
                    plot.setRenderer(datasetIndex, ren);
                }
                // "2" is lineStyle "area"
                else if (lineStyle.equalsIgnoreCase(AREA)) {
                    plot.setRenderer(datasetIndex, new XYAreaRenderer());
                }
                // "3" is lineStyle "dotted"
                else if (lineStyle.equalsIgnoreCase(DOTTED)) {
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(false, true);
                    ren.setShape(new Ellipse2D.Double(-width, -width, 2 * width, 2 * width));
                    plot.setRenderer(datasetIndex, ren);

                }
                // "4" is dashed
                else if (lineStyle.equalsIgnoreCase("4")) { // dashed
                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
                    renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND,
                            BasicStroke.JOIN_ROUND, 1.0f, new float[] { 4.0f * width, 4.0f * width }, 0.0f));
                    plot.setRenderer(datasetIndex, renderer);
                } else if (lineStyle.equalsIgnoreCase("5")) {
                    // lines and dots
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, true);
                    int thickness = 2 * width;
                    ren.setShape(new Ellipse2D.Double(-width, -width, thickness, thickness));
                    ren.setStroke(new BasicStroke(width));
                    plot.setRenderer(datasetIndex, ren);
                } else {
                    // default is lineStyle "line"
                    plot.setRenderer(datasetIndex, new XYLineAndShapeRenderer(true, false));
                }

                plot.getRenderer(datasetIndex).setSeriesPaint(seriesIndex, dd.getColor());

                // plot.getRenderer(datasetIndex).setShapesVisible(true);

                XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
                XYURLGenerator urlGenerator = new MetadataInURLGenerator(designDescriptions);

                plot.getRenderer(datasetIndex).setBaseToolTipGenerator(toolTipGenerator);
                plot.getRenderer(datasetIndex).setURLGenerator(urlGenerator);

                // GRID:
                // PROBLEM: JFreeChart only allows to switch the grid on/off
                // for the whole XYPlot. And the
                // grid will always be displayed for the first series in the
                // plot. I'll always show the
                // grid.
                // --> plot.setDomainGridlinesVisible(visible)

                // RANGE AXIS LABELS:
                if (isOverview) {
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelsVisible(false);
                    plot.getRangeAxisForDataset(datasetIndex).setTickMarksVisible(false);
                    plot.getRangeAxisForDataset(datasetIndex).setVisible(false);
                } else {
                    plot.getRangeAxisForDataset(datasetIndex).setLabelFont(label);
                    plot.getRangeAxisForDataset(datasetIndex).setLabelPaint(LABEL_COLOR);
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelFont(tickLabelDomain);
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelPaint(LABEL_COLOR);
                    StringBuilder unitOfMeasure = new StringBuilder();
                    unitOfMeasure.append(dd.getPhenomenon().getLabel());
                    String uomLabel = dd.getUomLabel();
                    if (uomLabel != null && !uomLabel.isEmpty()) {
                        unitOfMeasure.append(" (").append(uomLabel).append(")");
                    }
                    plot.getRangeAxisForDataset(datasetIndex).setLabel(unitOfMeasure.toString());
                }
            }
        }
    }
    return chart;
}

From source file:org.n52.server.sos.render.DiagramRenderer.java

/**
 * <pre>//from  www  .  ja va  2s.  c om
 * dataset :=  associated to one range-axis;
 * corresponds to one observedProperty;
 * may contain multiple series;
 * series :=   corresponds to a time series for one foi
 * </pre>
 * 
 * .
 * 
 * @param entireCollMap
 *            the entire coll map
 * @param options
 *            the options
 * @param begin
 *            the begin
 * @param end
 *            the end
 * @param compress
 * @return the j free chart
 */
public JFreeChart renderChart(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options,
        Calendar begin, Calendar end, boolean compress) {

    DesignDescriptionList designDescriptions = buildUpDesignDescriptionList(options);

    /*** FIRST RUN ***/
    JFreeChart chart = initializeTimeSeriesChart();
    chart.setBackgroundPaint(Color.white);

    if (!this.isOverview) {
        chart.addSubtitle(new TextTitle(ConfigurationContext.COPYRIGHT, new Font(LABEL_FONT, Font.PLAIN, 9),
                Color.black, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM,
                new RectangleInsets(0, 0, 20, 20)));
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.setDomainGridlinesVisible(options.getGrid());
    plot.setRangeGridlinesVisible(options.getGrid());

    // add additional datasets:
    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setRange(begin.getTime(), end.getTime());
    dateAxis.setDateFormatOverride(new SimpleDateFormat());

    // add all axes
    String[] phenomenaIds = options.getAllPhenomenIds();
    // all the axis indices to map them later
    HashMap<String, Integer> axes = new HashMap<String, Integer>();
    for (int i = 0; i < phenomenaIds.length; i++) {
        axes.put(phenomenaIds[i], i);
        plot.setRangeAxis(i, new NumberAxis(phenomenaIds[i]));
    }

    // list range markers
    ArrayList<ValueMarker> referenceMarkers = new ArrayList<ValueMarker>();
    HashMap<String, double[]> referenceBounds = new HashMap<String, double[]>();

    // create all TS collections
    for (int i = 0; i < options.getProperties().size(); i++) {

        TimeseriesProperties prop = options.getProperties().get(i);

        String phenomenonId = prop.getPhenomenon();

        TimeSeriesCollection dataset = createDataset(entireCollMap, prop, phenomenonId, compress);
        dataset.setGroup(new DatasetGroup(prop.getTimeseriesId()));
        XYDataset additionalDataset = dataset;

        NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenomenonId));

        if (this.isOverview) {
            axe.setAutoRange(true);
            axe.setAutoRangeIncludesZero(false);
        } else if (prop.getAxisUpperBound() == prop.getAxisLowerBound() || prop.isAutoScale()) {
            if (prop.isZeroScaled()) {
                axe.setAutoRangeIncludesZero(true);
            } else {
                axe.setAutoRangeIncludesZero(false);
            }
        } else {
            if (prop.isZeroScaled()) {
                if (axe.getUpperBound() < prop.getAxisUpperBound()) {
                    axe.setUpperBound(prop.getAxisUpperBound());
                }
                if (axe.getLowerBound() > prop.getAxisLowerBound()) {
                    axe.setLowerBound(prop.getAxisLowerBound());
                }
            } else {
                axe.setRange(prop.getAxisLowerBound(), prop.getAxisUpperBound());
                axe.setAutoRangeIncludesZero(false);
            }
        }

        plot.setDataset(i, additionalDataset);
        plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId));

        // set bounds new for reference values
        if (!referenceBounds.containsKey(phenomenonId)) {
            double[] bounds = new double[] { axe.getLowerBound(), axe.getUpperBound() };
            referenceBounds.put(phenomenonId, bounds);
        } else {
            double[] bounds = referenceBounds.get(phenomenonId);
            if (bounds[0] >= axe.getLowerBound()) {
                bounds[0] = axe.getLowerBound();
            }
            if (bounds[1] <= axe.getUpperBound()) {
                bounds[1] = axe.getUpperBound();
            }
        }

        double[] bounds = referenceBounds.get(phenomenonId);
        for (String string : prop.getReferenceValues()) {
            if (prop.getRefValue(string).show()) {
                Double value = prop.getRefValue(string).getValue();
                if (value <= bounds[0]) {
                    bounds[0] = value;
                } else if (value >= bounds[1]) {
                    bounds[1] = value;
                }
            }
        }

        Axis axis = prop.getAxis();
        if (axis == null) {
            axis = new Axis(axe.getUpperBound(), axe.getLowerBound());
        } else if (prop.isAutoScale()) {
            axis.setLowerBound(axe.getLowerBound());
            axis.setUpperBound(axe.getUpperBound());
            axis.setMaxY(axis.getMaxY());
            axis.setMinY(axis.getMinY());
        }
        prop.setAxisData(axis);
        this.axisMapping.put(prop.getTimeseriesId(), axis);

        for (String string : prop.getReferenceValues()) {
            if (prop.getRefValue(string).show()) {
                referenceMarkers.add(new ValueMarker(prop.getRefValue(string).getValue(),
                        Color.decode(prop.getRefValue(string).getColor()),
                        new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)));
            }
        }

        plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId));
    }

    for (ValueMarker valueMarker : referenceMarkers) {
        plot.addRangeMarker(valueMarker);
    }

    // show actual time
    ValueMarker nowMarker = new ValueMarker(System.currentTimeMillis(), Color.orange,
            new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f));
    plot.addDomainMarker(nowMarker);

    if (!this.isOverview) {
        Iterator<Entry<String, double[]>> iterator = referenceBounds.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, double[]> boundsEntry = iterator.next();
            String phenId = boundsEntry.getKey();
            NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenId));
            axe.setAutoRange(true);
            // add a margin 
            double marginOffset = (boundsEntry.getValue()[1] - boundsEntry.getValue()[0]) / 25;
            boundsEntry.getValue()[0] -= marginOffset;
            boundsEntry.getValue()[1] += marginOffset;
            axe.setRange(boundsEntry.getValue()[0], boundsEntry.getValue()[1]);
        }
    }

    /**** SECOND RUN ***/

    // set domain axis labels:
    plot.getDomainAxis().setLabelFont(label);
    plot.getDomainAxis().setLabelPaint(LABEL_COLOR);
    plot.getDomainAxis().setTickLabelFont(tickLabelDomain);
    plot.getDomainAxis().setTickLabelPaint(LABEL_COLOR);
    plot.getDomainAxis().setLabel(designDescriptions.getDomainAxisLabel());

    // define the design for each series:
    for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {
        TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(datasetIndex);

        for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) {

            String timeseriesId = (String) dataset.getSeries(seriesIndex).getKey();
            RenderingDesign dd = designDescriptions.get(timeseriesId);

            if (dd != null) {

                // LINESTYLE:
                String lineStyle = dd.getLineStyle();
                int width = dd.getLineWidth();
                if (this.isOverview) {
                    width = width / 2;
                    width = (width == 0) ? 1 : width;
                }
                // "1" is lineStyle "line"
                if (lineStyle.equalsIgnoreCase(LINE)) {
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, false);
                    ren.setStroke(new BasicStroke(width));
                    plot.setRenderer(datasetIndex, ren);
                }
                // "2" is lineStyle "area"
                else if (lineStyle.equalsIgnoreCase(AREA)) {
                    plot.setRenderer(datasetIndex, new XYAreaRenderer());
                }
                // "3" is lineStyle "dotted"
                else if (lineStyle.equalsIgnoreCase(DOTTED)) {
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(false, true);
                    ren.setShape(new Ellipse2D.Double(-width, -width, 2 * width, 2 * width));
                    plot.setRenderer(datasetIndex, ren);

                }
                // "4" is dashed
                else if (lineStyle.equalsIgnoreCase("4")) {
                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
                    renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND,
                            BasicStroke.JOIN_ROUND, 1.0f, new float[] { 4.0f * width, 4.0f * width }, 0.0f));
                    plot.setRenderer(datasetIndex, renderer);
                } else if (lineStyle.equalsIgnoreCase("5")) {
                    // lines and dots
                    XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, true);
                    int thickness = 2 * width;
                    ren.setShape(new Ellipse2D.Double(-width, -width, thickness, thickness));
                    ren.setStroke(new BasicStroke(width));
                    plot.setRenderer(datasetIndex, ren);
                } else {
                    // default is lineStyle "line"
                    plot.setRenderer(datasetIndex, new XYLineAndShapeRenderer(true, false));
                }

                plot.getRenderer(datasetIndex).setSeriesPaint(seriesIndex, dd.getColor());

                // plot.getRenderer(datasetIndex).setShapesVisible(true);

                XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
                XYURLGenerator urlGenerator = new MetadataInURLGenerator(designDescriptions);

                plot.getRenderer(datasetIndex).setBaseToolTipGenerator(toolTipGenerator);
                plot.getRenderer(datasetIndex).setURLGenerator(urlGenerator);

                // GRID:
                // PROBLEM: JFreeChart only allows to switch the grid on/off
                // for the whole XYPlot. And the
                // grid will always be displayed for the first series in the
                // plot. I'll always show the
                // grid.
                // --> plot.setDomainGridlinesVisible(visible)

                // RANGE AXIS LABELS:
                if (isOverview) {
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelsVisible(false);
                    plot.getRangeAxisForDataset(datasetIndex).setTickMarksVisible(false);
                    plot.getRangeAxisForDataset(datasetIndex).setVisible(false);
                } else {
                    plot.getRangeAxisForDataset(datasetIndex).setLabelFont(label);
                    plot.getRangeAxisForDataset(datasetIndex).setLabelPaint(LABEL_COLOR);
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelFont(tickLabelDomain);
                    plot.getRangeAxisForDataset(datasetIndex).setTickLabelPaint(LABEL_COLOR);
                    StringBuilder unitOfMeasure = new StringBuilder();
                    unitOfMeasure.append(dd.getPhenomenon().getLabel());
                    String uomLabel = dd.getUomLabel();
                    if (uomLabel != null && !uomLabel.isEmpty()) {
                        unitOfMeasure.append(" (").append(uomLabel).append(")");
                    }
                    plot.getRangeAxisForDataset(datasetIndex).setLabel(unitOfMeasure.toString());
                }
            }
        }
    }
    return chart;
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createXYZSeriesCollectionChart(
        final XYZSeriesCollectionChartDefinition chartDefinition) {
    JFreeChart chart = null;/*from  ww  w.j av  a  2  s  .  com*/
    // TODO Make the following accessible from the chartDefinition
    String domainAxisLabel = null;
    String rangeAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel)
            : new NumberAxis(domainAxisLabel);
    domainAxis.setAutoRangeIncludesZero(chartDefinition.isDomainIncludesZero());
    domainAxis.setAutoRangeStickyZero(chartDefinition.isDomainStickyZero());

    NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    rangeAxis.setAutoRangeIncludesZero(chartDefinition.isRangeIncludesZero());
    rangeAxis.setAutoRangeStickyZero(chartDefinition.isRangeStickyZero());

    BubbleRenderer renderer = null;

    // So far only Bubble charts are supported
    switch (chartDefinition.getChartType()) {
    case BUBBLE_CHART_TYPE:
        renderer = new BubbleRenderer();
        break;
    default:
        // should log an error if invalid chart type passed in - at least return null for no renderer
        return null;
    }

    if (tooltips) {
        // creating the label definition

        renderer.setToolTipGenerator(new StandardXYZToolTipGenerator(chartDefinition.getBubbleLabelContent(),
                chartDefinition.getXFormat(), chartDefinition.getYFormat(), chartDefinition.getZFormat()));
    }
    if (urls) {
        renderer.setURLGenerator(new StandardBubbleURLGenerator());
    }

    renderer.setMaxSize(chartDefinition.getMaxBubbleSize());
    renderer.setMaxZ(chartDefinition.getMaxZValue());

    XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);

    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;
}

From source file:net.sf.maltcms.chromaui.msviewer.ui.panel.MassSpectrumPanel.java

private void initChartComponents() {

    this.sc = new XYSeriesCollection();
    barDataset = new XYBarDataset(sc, barWidth);
    XYBarRenderer renderer = new XYBarRenderer(0.1d);
    StandardXYBarPainter sp = new StandardXYBarPainter();
    renderer.setBarPainter(sp);//from   w w w  . j  av a  2  s .  co  m
    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(false);
    NumberAxis intensityAxis = new NumberAxis("intensity");
    intensityAxis.setNumberFormatOverride(defaultNumberFormat);
    intensityAxis.setUpperMargin(0.10d);
    NumberAxis mzAxis = new NumberAxis("m/z");
    mzAxis.setAutoRangeIncludesZero(false);
    this.plot = new XYPlot(barDataset, mzAxis, intensityAxis, renderer);
    this.plot.setForegroundAlpha(0.85f);

    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);
    ((XYBarRenderer) plot.getRenderer()).setShadowVisible(false);
    ((XYBarRenderer) plot.getRenderer()).setDrawBarOutline(false);
    ((XYBarRenderer) plot.getRenderer()).setBaseFillPaint(Color.RED);
    ((XYBarRenderer) plot.getRenderer()).setBarPainter(new StandardXYBarPainter());
    plot.getRenderer().setBaseItemLabelsVisible(true);
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            Comparable comp = xyd.getSeriesKey(i);
            double x = xyd.getXValue(i, i1);
            double y = xyd.getYValue(i, i1);
            StringBuilder sb = new StringBuilder();
            sb.append(comp);
            sb.append(": ");
            sb.append("x=");
            sb.append(String.format("%.4f", x));
            sb.append(" y=");
            sb.append(String.format("%.4f", y));
            return sb.toString();
        }
    });
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    sc.addChangeListener(plot);
    JFreeChart msChart = new JFreeChart(this.plot);
    msChart.addChangeListener(this.defaultNumberFormat);
    //      System.out.println("Creating ms chart 3");
    this.cp = new ContextAwareChartPanel(msChart, true, true, true, true, true);
    this.cp.setInitialDelay(1);
    this.cp.getChart().getLegend().setVisible(true);
    this.cp.setMouseWheelEnabled(true);
    this.clearActionPerformed(null);
    this.jPanel2.removeAll();
    this.jPanel2.add(cp);
    this.jPanel2.repaint();
    this.massLabelsSpinner.setValue(topK);
}

From source file:hr.restart.util.chart.ChartXYZ.java

/**
  * Creates a LINE CHART.// w  ww. j  ava  2 s.  c  om
  * 
  * @param dataset The org.jfree.data.CategoryDataset
  * @param title The title
  * @return org.jfree.chart.JFreeChart
  */
final private JFreeChart createLineChart(final CategoryDataset dataset, String title) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart(title, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    //print the subtitles
    java.util.List subs = getSubtitles();
    if (subs != null)
        for (int i = 0; i < subs.size(); i++) {
            chart.addSubtitle(new TextTitle(subs.get(i).toString()));
        }

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final StandardLegend legend = (StandardLegend) chart.getLegend();
    legend.setDisplaySeriesShapes(true);
    legend.setShapeScaleX(1.5);
    legend.setShapeScaleY(1.5);
    legend.setDisplaySeriesLines(true);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //plot.setBackgroundPaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setDrawShapes(true);
    adjustLineRenderer(renderer);

    //        renderer.setSeriesStroke(
    //            0, new BasicStroke(
    //                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
    //                1.0f, new float[] {10.0f, 6.0f}, 0.0f
    //            )
    //        );
    //        renderer.setSeriesStroke(
    //            1, new BasicStroke(
    //                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
    //                1.0f, new float[] {6.0f, 6.0f}, 0.0f
    //            )
    //        );
    //        renderer.setSeriesStroke(
    //            2, new BasicStroke(
    //                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
    //                1.0f, new float[] {2.0f, 6.0f}, 0.0f
    //            )
    //        );
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createXYSeriesCollectionChart(
        final XYSeriesCollectionChartDefinition chartDefinition) {
    JFreeChart chart = null;//w  w w  .  j  a v a  2 s  .c  om
    // TODO Make the following accessible from the chartDefinition
    String domainAxisLabel = null;
    String rangeAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel)
            : new NumberAxis(domainAxisLabel);
    domainAxis.setAutoRangeIncludesZero(chartDefinition.isDomainIncludesZero());
    domainAxis.setAutoRangeStickyZero(chartDefinition.isDomainStickyZero());
    ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);

    AbstractXYItemRenderer renderer = null;
    switch (chartDefinition.getChartType()) {
    case LINE_CHART_TYPE:
        renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer()
                : new XYLineAndShapeRenderer(true, false);
        ((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
        ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
        break;
    case AREA_CHART_TYPE:
        renderer = new XYAreaRenderer();
        break;
    case STEP_CHART_TYPE:
        renderer = new XYStepRenderer();
        break;
    case STEP_AREA_CHART_TYPE:
        renderer = new XYStepAreaRenderer();
        break;
    case DIFFERENCE_CHART_TYPE:
        renderer = new XYDifferenceRenderer();
        break;
    case DOT_CHART_TYPE:
        renderer = new XYDotRenderer();
        ((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
        ((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
        break;
    default:
        // should log an error if invalid chart type passed in - at least return null for no renderer
        return null;
    }

    if (renderer != null && legend) {
        renderer.setLegendItemURLGenerator(new StandardXYSeriesLabelGenerator());
    }

    if (tooltips) {
        XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(),
                new DecimalFormat(chartDefinition.getTooltipXFormat()),
                new DecimalFormat(chartDefinition.getTooltipYFormat()));
        renderer.setToolTipGenerator(generator);
    }

    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(),
            chartDefinition.getLineWidth()));

    XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);

    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initRangeAxis(ChartDefinitionVO chartDefinition) {

    int axisNumber = 0;
    int datasetNumber = 0;
    for (AxisDefinitionVO axisDefinition : chartDefinition.getAxisDefinitions()) {

        // configure the axis
        NumberAxis rangeAxis = new NumberAxis(axisDefinition.getLabel());

        // set the properteis
        rangeAxis.setAutoRange(axisDefinition.isAutoRange());
        if (axisDefinition.isAutoRange()) {
            rangeAxis.setAutoRangeIncludesZero(axisDefinition.isAutoRangeIncludesZero());
        } else {//  w ww.j av a2  s  . c  o m
            rangeAxis.setLowerBound(axisDefinition.getLowerBound());
            rangeAxis.setUpperBound(axisDefinition.getUpperBound());
        }

        if (axisDefinition.getNumberFormat() != null) {
            rangeAxis.setNumberFormatOverride(new DecimalFormat(axisDefinition.getNumberFormat())); //##0.00% / "##0.000"
        }

        getPlot().setRangeAxis(axisNumber, rangeAxis);
        getPlot().setRangeAxisLocation(axisNumber, AxisLocation.BOTTOM_OR_RIGHT);

        // initialize datasets
        for (DatasetDefinitionVO datasetDefinition : axisDefinition.getDatasetDefinitions()) {

            XYDataset dataset;
            if (DatasetType.TIME.equals(datasetDefinition.getType())) {

                // create the time series collection
                dataset = new TimeSeriesCollection();
                getPlot().setDataset(datasetNumber, dataset);

                // create the renderer
                XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setBaseShapesVisible(false);

                getPlot().setRenderer(datasetNumber, renderer);

            } else if (DatasetType.OHLC.equals(datasetDefinition.getType())) {

                // create the ohlc series collection
                dataset = new OHLCSeriesCollection();
                getPlot().setDataset(datasetNumber, dataset);

                // create the renderer
                HideableCandlestickRenderer renderer = new HideableCandlestickRenderer();
                renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator(
                        new SimpleDateFormat("dd.MM.yyyy kk:mm:ss"), NumberFormat.getInstance()));
                getPlot().setRenderer(datasetNumber, renderer);

            } else {
                throw new IllegalArgumentException("illegal dataset type " + datasetDefinition.getType());
            }

            getPlot().mapDatasetToRangeAxis(datasetNumber, axisNumber);

            // initialize series
            initSeries(datasetNumber, datasetDefinition, dataset);

            datasetNumber++;
        }

        axisNumber++;
    }
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates and returns a default instance of a box and whisker chart.    
 *    /*from  w w w .j  a v a  2  s. c o  m*/
 * @param title  the chart title (<code>null</code> permitted).    
 * @param timeAxisLabel  a label for the time axis (<code>null</code>     
 *                       permitted).    
 * @param valueAxisLabel  a label for the value axis (<code>null</code>     
 *                        permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 *    
 * @return A box and whisker chart.    
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String timeAxisLabel, String valueAxisLabel,
        BoxAndWhiskerXYDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

}