Example usage for org.jfree.chart.plot XYPlot setRangeAxisLocation

List of usage examples for org.jfree.chart.plot XYPlot setRangeAxisLocation

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRangeAxisLocation.

Prototype

public void setRangeAxisLocation(int index, AxisLocation location) 

Source Link

Document

Sets the location for a range axis and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GOESChartUIComponent.java

/***********************************************************************************************
 * Customise the XYPlot of a new chart, e.g. for fixed range axes.
 *
 * @param datasettype/* w ww. j av  a  2  s .  c  o m*/
 * @param primarydataset
 * @param secondarydatasets
 * @param updatetype
 * @param displaylimit
 * @param channelselector
 * @param debug
 *
 * @return JFreeChart
 */

public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset,
        final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit,
        final ChannelSelectorUIComponentInterface channelselector, final boolean debug) {
    final JFreeChart jFreeChart;

    // A plain Chart is an XYPlot
    // with a DateAxis for the x-axis (index 0) and a NumberAxis for the y-axis (index 0).
    // The default renderer is an XYLineAndShapeRenderer
    jFreeChart = ChartHelper.createChart(primarydataset,
            ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug),
            getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit,
            channelselector, debug);

    // Customise the Chart for GOES data
    // Channels 0 & 1 are Data on a LogarithmicAxis,
    // Channel 2 is Ratio on a NumberAxis
    if (jFreeChart != null) {
        final String strLabelFlux;
        final String strLabelRatio;
        final XYPlot plot;
        final LogarithmicAxis axisFlux;
        final DateAxis axisDate;

        // The set of Metadata available should include the Instrument
        // and any items from the current observation
        strLabelFlux = MetadataHelper.getMetadataValueByKey(getMetadata(),
                MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey()
                        + MetadataDictionary.SUFFIX_SERIES_ZERO);
        strLabelRatio = MetadataHelper.getMetadataValueByKey(getMetadata(),
                MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey()
                        + MetadataDictionary.SUFFIX_SERIES_ONE);

        plot = jFreeChart.getXYPlot();

        //----------------------------------------------------------------------------------
        // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis
        // The RangeAxis at index 0 is the LogarithmicAxis, to be used by Channels 0 & 1 (Data)

        axisFlux = new LogarithmicAxis(strLabelFlux);
        axisFlux.setRange(1.0E-09, 1.0E-02);
        axisFlux.setAllowNegativesFlag(false);
        axisFlux.setLog10TickLabelsFlag(true);
        plot.setRangeAxis(0, axisFlux);

        // Map the dataset to the axis
        plot.setDataset(INDEX_FLUX, primarydataset);
        plot.mapDatasetToRangeAxis(0, 0);
        plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);

        //----------------------------------------------------------------------------------
        // Customise the DomainAxis at index 0

        axisDate = (DateAxis) plot.getDomainAxis();

        // Showing the YYYY-MM-DD makes a very long label...
        // ToDo Consider ThreadLocal
        axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

        // Now customise the Flux renderer to improve legend visibility
        // Use the same colours as on http://www.swpc.noaa.gov/
        // blue=0.5 - 4.0A red=1.0 - 8.0A
        ChartUIHelper.customisePlotRenderer(plot, INDEX_FLUX);

        //----------------------------------------------------------------------------------
        // Set the RangeAxis at index 1 to a new NumberAxis, to be used by Channel 2 (Ratio)

        if ((secondarydatasets != null) && (secondarydatasets.size() == 1)) {
            final NumberAxis axisRatio;
            final XYLineAndShapeRenderer rendererRatio;

            axisRatio = new NumberAxis(strLabelRatio);
            plot.setRangeAxis(1, axisRatio);

            // The RangeAxis at index 1 is the NumberAxis, to be used by Channel 2
            plot.setDataset(INDEX_RATIO, secondarydatasets.get(0));
            plot.mapDatasetToRangeAxis(1, 1);
            plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);

            rendererRatio = new XYLineAndShapeRenderer();
            rendererRatio.setLinesVisible(true);
            rendererRatio.setShapesVisible(false);
            // Channel 2 is Ratio
            rendererRatio.setSeriesPaint(0, ChartUIHelper.getStandardColour(2).getColor());
            rendererRatio.setLegendLine(SHAPE_LEGEND);

            plot.setRenderer(INDEX_RATIO, rendererRatio);
            //ChartHelper.customisePlotRenderer(plot, INDEX_RATIO);
        }
    }

    return (jFreeChart);
}

From source file:netplot.GenericPlotPanel.java

void genericConfig(JFreeChart chart, XYPlot plot, int plotIndex) {
    if (!enableLegend) {
        chart.removeLegend();//from w  w w .  j  ava  2 s  . c om
    }

    XYItemRenderer xyItemRenderer = plot.getRenderer();
    //May also be XYBarRenderer
    if (xyItemRenderer instanceof XYLineAndShapeRenderer) {
        XYToolTipGenerator xyToolTipGenerator = xyItemRenderer.getBaseToolTipGenerator();
        //If currently an XYLineAndShapeRenderer replace it so that we inc the colour for every plotIndex
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(linesEnabled, shapesEnabled);
        //Ensure we don't loose the tool tips on the new renderer
        renderer.setBaseToolTipGenerator(xyToolTipGenerator);
        renderer.setBasePaint(getPlotColour(plotIndex));
        renderer.setSeriesStroke(0, new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),
                true);
        plot.setRenderer(plotIndex, renderer);
    }

    //If we have a new y axis then we need a new data set
    if (yAxisName != null && yAxisName.length() > 0) {
        if (logYAxis) {
            LogAxis yAxis = new LogAxis(yAxisName);
            yAxis.setAutoRange(false);
            yAxis.setNumberFormatOverride(new LogFormat(10, "10", true));
            yAxis.setRange(minScaleValue, maxScaleValue);
            yAxis.setLowerBound(minScaleValue);
            yAxis.setUpperBound(maxScaleValue);
            plot.setRangeAxis(yAxisIndex, yAxis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        } else {
            NumberAxis axis = new NumberAxis(yAxisName);
            axis.setAutoRangeIncludesZero(zeroOnYScale);
            if (autoScaleEnabled) {
                axis.setAutoRange(true);
            } else {
                Range range = new Range(minScaleValue, maxScaleValue);
                axis.setRangeWithMargins(range, true, true);
            }
            if (yAxisTickCount > 0) {
                NumberTickUnit tick = new NumberTickUnit(yAxisTickCount);
                axis.setTickUnit(tick);
            }
            plot.setRangeAxis(yAxisIndex, axis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        }
        yAxisIndex++;
    }
    plot.mapDatasetToRangeAxis(plotIndex, yAxisIndex - 1);
    ValueAxis a = plot.getDomainAxis();
    if (xAxisName.length() > 0) {
        a.setLabel(xAxisName);
    }
    //We can enable/disable zero on the axis if we have a NumberAxis
    if (a instanceof NumberAxis) {
        ((NumberAxis) a).setAutoRangeIncludesZero(zeroOnXScale);
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Processes a string that indicates the axes that should be visible on
 * the plot.//from w  w w.j  av  a  2s . c  o  m
 *
 * @param plot  the plot.
 * @param axisStr  the axis specification.
 * @param axes  a list that will be populated with any axes added to the
 *              plot.
 */
private static void processAxisStr(XYPlot plot, String axisStr, List axes) {
    int xAxisCount = 0;
    int yAxisCount = 0;
    for (int i = 0; i < axisStr.length(); i++) {
        char c = axisStr.charAt(i);
        if (c == 'x') {
            if (xAxisCount == 0) {
                Axis xAxis = plot.getDomainAxis();
                xAxis.setTickMarksVisible(true);
                xAxis.setTickLabelsVisible(true);
                axes.add(xAxis);
                xAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setDomainAxis(xAxisCount, axis);
                plot.setDomainAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                xAxisCount++;
            }
        } else if (c == 'y') {
            if (yAxisCount == 0) {
                Axis yAxis = plot.getRangeAxis();
                yAxis.setTickMarksVisible(true);
                yAxis.setTickLabelsVisible(true);
                axes.add(yAxis);
                yAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setRangeAxis(yAxisCount, axis);
                plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                yAxisCount++;
            }
        } else if (c == 'r') {
            GValueAxis axis = new GValueAxis();
            plot.setRangeAxis(yAxisCount, axis);
            plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_RIGHT);
            axes.add(axis);
            yAxisCount++;
        } else if (c == 't') {
            GValueAxis axis = new GValueAxis();
            plot.setDomainAxis(xAxisCount, axis);
            plot.setDomainAxisLocation(xAxisCount, AxisLocation.TOP_OR_LEFT);
            axes.add(axis);
            xAxisCount++;
        } else if (c == ',') {
            // nothing to do
        } else {
            throw new RuntimeException("Bad character " + c);
        }
    }

}

From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java

/**
 * Generates a chart in PNG format.//w  w w  .j  ava  2 s .c om
 * @param outputFile the output file, it should exist.
 * @param pxWidth the image width in pixels.
 * @param pxHeight the image height in pixels.
 * @param chartTitle the chart title, may be null.
 * @param xAxisTitle the x axis title
 * @param yDataSeriesRange the axis range (null for auto)
 * @param yDataSeriesTitles the Y axis titles.
 * @param timeValuesInSeconds the time values in seconds
 * @param yDataSeries the Y axis value series.
 * @param yDataSeriesColors the Y axis value series drawing colors.
 * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix
 * @param drawBorder draw, or not, the border.
 * @param backgroundColor the chart background color.
 */
final void generatePngChart(File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle,
        String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange,
        double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder,
        Color backgroundColor) {

    // Domain axis
    NumberAxis xAxis = new NumberAxis(xAxisTitle);
    xAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    xAxis.setLabelPaint(Color.black);
    xAxis.setTickLabelPaint(Color.black);

    double maxSeconds = getMaxValue(timeValuesInSeconds);
    TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds);
    xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep));
    double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds);

    String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name());
    xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'"));

    // First dataset
    String firstDataSetTitle = yDataSeriesTitles[0];
    XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]);
    Color firstDataSetColor = yDataSeriesColors[0];

    // First range axis
    NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle);

    firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    setAxisRange(firstYAxis, yDataSeriesRange[0]);
    firstYAxis.setLabelPaint(firstDataSetColor);
    firstYAxis.setTickLabelPaint(firstDataSetColor);
    String firstAxisTickSuffix = yDataSeriesTickSuffix[0];
    if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) {
        firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'"));
    }

    // Create the plot with domain axis and first range axis
    XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null);

    XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(firstRenderer);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    firstRenderer.setSeriesPaint(0, firstDataSetColor);

    // Now iterate on next axes
    for (int i = 1; i < yDataSeries.length; i++) {
        // Create axis
        String seriesTitle = yDataSeriesTitles[i];
        Color seriesColor = yDataSeriesColors[i];
        NumberAxis yAxis = new NumberAxis(seriesTitle);

        yAxis.setFixedDimension(CHART_AXIS_DIMENSION);
        setAxisRange(yAxis, yDataSeriesRange[i]);

        yAxis.setLabelPaint(seriesColor);
        yAxis.setTickLabelPaint(seriesColor);

        String yAxisTickSuffix = yDataSeriesTickSuffix[i];
        if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) {
            yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'"));
        }

        // Create dataset and add axis to plot
        plot.setRangeAxis(i, yAxis);
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT);
        plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i]));
        plot.mapDatasetToRangeAxis(i, i);
        XYItemRenderer renderer = new StandardXYItemRenderer();
        renderer.setSeriesPaint(0, seriesColor);
        plot.setRenderer(i, renderer);
    }

    // Create the chart
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    // Customize rendering
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);

    // Render image
    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight);
    } catch (IOException e) {
        LOG.error("Chart export failed", e);
    }
}

From source file:org.ramadda.data.services.PointFormHandler.java

/**
 * _more_//from   w  w  w  .  jav  a 2s  .co  m
 *
 * @param request _more_
 * @param pointEntry _more_
 * @param plotInfo _more_
 *
 * @return _more_
 *
 * @throws Exception _more_
 */
public BufferedImage makeTimeseriesImage(Request request, PointEntry pointEntry, final PlotInfo plotInfo)
        throws Exception {

    Entry entry = pointEntry.getEntry();
    int width = TIMESERIES_WIDTH;
    int height = TIMESERIES_HEIGHT;
    long numRecords = pointEntry.getNumRecords();
    final int numPointsToPlot = request.get(ARG_NUMPOINTS, TIMESERIES_POINTS);
    final int[] cnt = { 0 };
    final List<TimeSeries> series = new ArrayList<TimeSeries>();

    final List<RecordField> tmpFields = pointEntry.getRecordFile().getChartableFields();

    final List<RecordField> fields = new ArrayList<RecordField>();

    if (request.get(ARG_CHART_SHOW + FIELD_ALTITUDE, false)) {
        fields.add(new RecordField(FIELD_ALTITUDE, LABEL_ALTITUDE, "", -1, UNIT_M));
    }

    for (RecordField attr : tmpFields) {
        if (request.get(ARG_CHART_SHOW + attr.getName(), false)) {
            fields.add(attr);
        }
    }

    if ((fields.size() == 0) && (tmpFields.size() > 0)) {
        fields.add(tmpFields.get(0));
        request.put(ARG_CHART_SHOW + tmpFields.get(0).getName(), "true");
    }

    for (RecordField attr : fields) {
        series.add(new TimeSeries(attr.getLabel()));
    }

    RecordVisitor visitor = new BridgeRecordVisitor(getOutputHandler()) {
        public boolean doVisitRecord(RecordFile file, VisitInfo visitInfo, Record record) {
            PointRecord pointRecord = (PointRecord) record;
            for (int fieldCnt = 0; fieldCnt < fields.size(); fieldCnt++) {
                RecordField field = fields.get(fieldCnt);
                double value;
                //Check for altitude
                if (field.getParamId() < 0) {
                    value = pointRecord.getAltitude();
                } else {
                    value = record.getValue(field.getParamId());
                }
                long time = record.getRecordTime();
                series.get(fieldCnt).add(new FixedMillisecond(time), value);
            }
            plotInfo.setIndex(pointRecord.index);
            cnt[0]++;

            return true;
        }
    };

    long t1 = System.currentTimeMillis();
    int skip = (int) (numRecords / numPointsToPlot);
    getRecordJobManager().visitSequential(request, pointEntry, visitor, new VisitInfo(skip));
    long t2 = System.currentTimeMillis();

    JFreeChart chart = createTimeseriesChart(request, entry, new TimeSeriesCollection(), null);
    long t3 = System.currentTimeMillis();
    XYPlot plot = (XYPlot) chart.getPlot();
    int lineCnt = 0;
    int[] colorCnt = { 0 };
    int numberOfAxisLegends = 0;

    Hashtable<String, double[]> valueRanges = new Hashtable<String, double[]>();

    for (int extraCnt = 0; extraCnt < series.size(); extraCnt++) {
        TimeSeries timeSeries = series.get(extraCnt);
        RecordField field = fields.get(extraCnt);
        String unit = field.getUnit();
        if ((unit != null) && (unit.length() == 0)) {
            unit = null;
        }

        if (unit == null) {
            unit = extraCnt + "";
        }
        if (unit == null) {
            continue;
        }
        double max = timeSeries.getMaxY();
        double min = timeSeries.getMinY();
        double[] range = valueRanges.get(unit);
        if (range == null) {
            range = new double[] { min, max };
            valueRanges.put(unit, range);
        } else {
            range[0] = Math.min(range[0], min);
            range[1] = Math.max(range[1], max);
        }
    }

    Hashtable<String, NumberAxis> seenAxis = new Hashtable<String, NumberAxis>();
    for (int extraCnt = 0; extraCnt < series.size(); extraCnt++) {
        TimeSeries timeSeries = series.get(extraCnt);
        RecordField field = fields.get(extraCnt);

        String unit = field.getUnit();
        if ((unit != null) && (unit.length() == 0)) {
            unit = null;
        }

        TimeSeriesCollection dataset2 = new TimeSeriesCollection();
        dataset2.addSeries(timeSeries);
        NumberAxis axis = new NumberAxis(field.getLabel());
        numberOfAxisLegends++;
        if (unit != null) {
            double[] range = valueRanges.get(unit);
            axis.setRange(range[0], range[1]);
            NumberAxis seenOne = seenAxis.get(unit);
            if (seenOne == null) {
                seenAxis.put(unit, axis);
            } else {
                seenOne.setLabel(seenOne.getLabel() + "/" + field.getLabel());
                axis.setVisible(false);
                numberOfAxisLegends--;
            }
        } else {
            axis.setAutoRange(true);
            axis.setAutoRangeIncludesZero(true);
        }

        plot.setRangeAxis(lineCnt, axis);
        plot.setDataset(lineCnt, dataset2);
        plot.mapDatasetToRangeAxis(lineCnt, lineCnt);
        plot.setRangeAxisLocation(lineCnt, AxisLocation.BOTTOM_OR_RIGHT);

        StandardXYItemRenderer renderer = new MyStandardXYItemRenderer(plotInfo);
        renderer.setSeriesPaint(0, getColor(request, ARG_CHART_COLOR + field.getName(), colorCnt));
        plot.setRenderer(lineCnt, renderer);
        lineCnt++;
    }

    AxisSpace axisSpace = new AxisSpace();
    axisSpace.setRight(TIMESERIES_AXIS_WIDTHPER * numberOfAxisLegends);
    plot.setFixedRangeAxisSpace(axisSpace);

    long t4 = System.currentTimeMillis();
    BufferedImage newImage = chart.createBufferedImage(width + (numberOfAxisLegends * TIMESERIES_AXIS_WIDTHPER),
            height);

    long t5 = System.currentTimeMillis();

    //        System.err.println("Time series  cnt:" + cnt[0] + " " + (t2 - t1) + " "  + (t3 - t2) + " " + (t4 - t3) + " " + (t5 - t4));
    return newImage;
}

From source file:org.ramadda.geodata.cdmdata.GridPointOutputHandler.java

/**
 * Output the timeseries image//w w w.  j  av  a2s. c  o m
 *
 * @param request the request
 * @param entry  the entry
 * @param f  the file
 *
 * @return  the image
 *
 * @throws Exception  problem creating image
 */
private Result outputTimeSeriesImage(Request request, Entry entry, File f) throws Exception {

    StringBuffer sb = new StringBuffer();
    //sb.append(getHeader(request, entry));
    sb.append(header(msg("Chart")));

    TimeSeriesCollection dummy = new TimeSeriesCollection();
    JFreeChart chart = createChart(request, entry, dummy);
    XYPlot xyPlot = (XYPlot) chart.getPlot();

    Hashtable<String, MyTimeSeries> seriesMap = new Hashtable<String, MyTimeSeries>();
    List<MyTimeSeries> allSeries = new ArrayList<MyTimeSeries>();
    int paramCount = 0;
    int colorCount = 0;
    boolean axisLeft = true;
    Hashtable<String, List<ValueAxis>> axisMap = new Hashtable<String, List<ValueAxis>>();
    Hashtable<String, double[]> rangeMap = new Hashtable<String, double[]>();
    List<String> units = new ArrayList<String>();
    List<String> paramUnits = new ArrayList<String>();
    List<String> paramNames = new ArrayList<String>();

    long t1 = System.currentTimeMillis();
    String contents = IOUtil.readContents(getStorageManager().getFileInputStream(f));
    List<String> lines = StringUtil.split(contents, "\n", true, true);
    String header = lines.get(0);
    String[] headerToks = header.split(",");
    for (int i = 0; i < headerToks.length; i++) {
        paramNames.add(getParamName(headerToks[i]));
        paramUnits.add(getUnitFromName(headerToks[i]));
    }
    boolean hasLevel = paramNames.get(3).equals("vertCoord");

    boolean readHeader = false;
    for (String line : lines) {
        if (!readHeader) {
            readHeader = true;

            continue;
        }
        String[] lineTokes = line.split(",");
        Date date = DateUtil.parse(lineTokes[0]);
        int startIdx = hasLevel ? 4 : 3;
        for (int i = startIdx; i < lineTokes.length; i++) {
            double value = Double.parseDouble(lineTokes[i]);
            if (value != value) {
                continue;
            }
            List<ValueAxis> axises = null;
            double[] range = null;
            String u = paramUnits.get(i);
            String paramName = paramNames.get(i);
            String formatName = paramName.replaceAll("_", " ");
            String formatUnit = ((u == null) || (u.length() == 0)) ? "" : "[" + u + "]";
            if (u != null) {
                axises = axisMap.get(u);
                range = rangeMap.get(u);
                if (axises == null) {
                    axises = new ArrayList<ValueAxis>();
                    range = new double[] { value, value };
                    rangeMap.put(u, range);
                    axisMap.put(u, axises);
                    units.add(u);
                }
                range[0] = Math.min(range[0], value);
                range[1] = Math.max(range[1], value);
            }
            MyTimeSeries series = seriesMap.get(paramName);
            if (series == null) {
                paramCount++;
                TimeSeriesCollection dataset = new TimeSeriesCollection();
                series = new MyTimeSeries(formatName, FixedMillisecond.class);
                allSeries.add(series);
                ValueAxis rangeAxis = new NumberAxis(formatName + " " + formatUnit);
                if (axises != null) {
                    axises.add(rangeAxis);
                }
                XYItemRenderer renderer = new XYAreaRenderer(XYAreaRenderer.LINES);
                if (colorCount >= HtmlUtils.COLORS.length) {
                    colorCount = 0;
                }
                renderer.setSeriesPaint(0, HtmlUtils.COLORS[colorCount]);
                colorCount++;
                xyPlot.setRenderer(paramCount, renderer);
                xyPlot.setRangeAxis(paramCount, rangeAxis, false);
                AxisLocation side = (axisLeft ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT);
                axisLeft = !axisLeft;
                xyPlot.setRangeAxisLocation(paramCount, side);

                dataset.setDomainIsPointsInTime(true);
                dataset.addSeries(series);
                seriesMap.put(paramNames.get(i), series);
                xyPlot.setDataset(paramCount, dataset);
                xyPlot.mapDatasetToRangeAxis(paramCount, paramCount);
            }
            //series.addOrUpdate(new FixedMillisecond(pointData.date),value);
            TimeSeriesDataItem item = new TimeSeriesDataItem(new FixedMillisecond(date), value);
            series.addItem(item);
        }
    }

    for (MyTimeSeries timeSeries : allSeries) {
        timeSeries.finish();
    }

    for (String unit : units) {
        List<ValueAxis> axises = axisMap.get(unit);
        double[] range = rangeMap.get(unit);
        for (ValueAxis rangeAxis : axises) {
            rangeAxis.setRange(new org.jfree.data.Range(range[0], range[1]));
        }
    }

    long t2 = System.currentTimeMillis();

    BufferedImage newImage = chart.createBufferedImage(request.get(ARG_IMAGE_WIDTH, 1000),
            request.get(ARG_IMAGE_HEIGHT, 400));
    long t3 = System.currentTimeMillis();
    //System.err.println("timeseries image time:" + (t2 - t1) + " "
    //                   + (t3 - t2));

    File file = getStorageManager().getTmpFile(request, "point.png");
    ImageUtils.writeImageToFile(newImage, file);
    InputStream is = getStorageManager().getFileInputStream(file);
    Result result = new Result("", is, "image/png");

    return result;

}

From source file:v800_trainer.JUebersicht.java

public JPanel Update_Uebersicht(JCicloTronic JTronicHandle) {

    int i;// www.  java2  s  .  com
    Day xTime[];
    Today = new GregorianCalendar();
    double y1Werte[];
    double y2Werte[];
    double y3Werte[];
    double y4Werte[];
    double y5Werte[];
    double y6Werte[];
    double y7Werte[];
    double y8Werte[];
    double y9Werte[];
    double y10Werte[];
    double SummeZeit = 0;
    double Summekm = 0;
    double Summehm = 0;
    double SummeZeit12Mon = 0;
    double Summekm12Mon = 0;
    double Summehm12Mon = 0;
    int AnzahlJahre = 0;
    int Selektiert = 0;
    int SelektiertVergl = 0;
    int Jahr;
    int Linecount = 0;
    boolean Vergleich = false;
    XYItemRenderer renderer;
    XYBarRenderer rendererb;

    JFreeChart chart;

    AnzahlJahre = JTronicHandle.Auswahl_bersicht.getItemCount();
    Selektiert = JTronicHandle.Auswahl_bersicht.getSelectedIndex();
    SelektiertVergl = JTronicHandle.JahrVergleich.getSelectedIndex();
    if (SelektiertVergl == 0 || Selektiert == SelektiertVergl - 1)
        Vergleich = false;
    else
        Vergleich = true;

    xTime = new Day[366];

    y1Werte = new double[366];
    y2Werte = new double[366];
    y3Werte = new double[366];
    y4Werte = new double[366];
    y5Werte = new double[366];
    y6Werte = new double[366];
    y7Werte = new double[366];
    y8Werte = new double[366];
    y9Werte = new double[366];
    y10Werte = new double[366];
    TimeSeries dataset;

    dataset = new TimeSeries("dummy");

    dataset.add(new Day(1, 1, 1900), 1);

    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

    chart = ChartFactory.createTimeSeriesChart(
            "Jahresbersicht " + JTronicHandle.Auswahl_bersicht.getSelectedItem().toString(), "Zeit", "",
            dataset1, true, true, true);

    XYToolTipGenerator ToolTip = new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            (DateFormat) new SimpleDateFormat("dd.MM"), NumberFormat.getInstance());

    if (SelektiertVergl != 0)
        chart.addSubtitle(new TextTitle(
                "Vergleich mit Jahr " + JTronicHandle.JahrVergleich.getSelectedItem().toString()));
    chart.setBackgroundPaint(Color.white);

    JTronicHandle.applyChartTheme(chart);

    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(false);
    plot.setDomainCrosshairLockedOnData(false);
    if (!JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
        DateAxis MyAxis = new DateAxis();
        MyAxis = (DateAxis) plot.getDomainAxis();
        MyAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
        MyAxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

        plot.setDomainGridlinesVisible(false);

    }

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);

    plot.getDomainAxis().setTickLabelInsets(new RectangleInsets(2.0, 1.0, 2.0, 1.0));

    Jahr = Integer.parseInt(JTronicHandle.Auswahl_bersicht.getSelectedItem().toString());

    for (i = 0; i < 366; i++) {
        SummeZeit12Mon += (double) Zeit[Selektiert + 1][i];
        Summekm12Mon += (double) kmJahr[Selektiert + 1][i];
        Summehm12Mon += (double) HmJahr[Selektiert + 1][i];

    }

    y4Werte[0] = SummeZeit12Mon;
    y5Werte[0] = Summekm12Mon;
    y6Werte[0] = Summehm12Mon;

    xTime[0] = new Day(31, 12, Jahr - 1);
    for (i = 1; i < 366; i++) {
        try {
            xTime[i] = new Day(xTime[i - 1].next().getStart());

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Exception GregorianCalender  " + e, "Achtung!",
                    JOptionPane.ERROR_MESSAGE);
        }

        if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
            SummeZeit += (double) Zeit[Selektiert][i];
            Summekm += (double) kmJahr[Selektiert][i];
            Summehm += (double) HmJahr[Selektiert][i];
            y1Werte[i] = SummeZeit;
            y2Werte[i] = Summekm;
            y3Werte[i] = Summehm;

            y4Werte[i] = y4Werte[i - 1] - (double) Zeit[Selektiert + 1][i] + (double) Zeit[Selektiert][i];
            y5Werte[i] = y5Werte[i - 1] - (double) kmJahr[Selektiert + 1][i] + (double) kmJahr[Selektiert][i];
            y6Werte[i] = y6Werte[i - 1] - (double) HmJahr[Selektiert + 1][i] + (double) HmJahr[Selektiert][i];

        } else {
            Day n = new Day(1, xTime[i].getMonth(), xTime[i].getYear());
            try {
                Kalender = new GregorianCalendar(xTime[i].getYear(), xTime[i].getMonth() - 1, 1);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Exception GregorianCalender  " + e, "Achtung!",
                        JOptionPane.ERROR_MESSAGE);

            }
            int j = (int) Kalender.get(Kalender.DAY_OF_YEAR);
            for (int m = 0; m < 6; m++) {
                y1Werte[j + m + 1] += (double) Zeit[Selektiert][i];
                y2Werte[j + m + 11] += (double) kmJahr[Selektiert][i];
                y3Werte[j + m + 21] += (double) HmJahr[Selektiert][i];

            }
        }

    }

    dataset = new TimeSeries("Trainingszeit " + JTronicHandle.Auswahl_bersicht.getSelectedItem().toString());
    for (i = 0; i < 366; i++) {
        dataset.add(xTime[i], y1Werte[i]);
    }

    dataset1 = new TimeSeriesCollection(dataset);
    NumberAxis axis = new NumberAxis();
    try {
        axis = (NumberAxis) plot.getRangeAxis().clone();
    } catch (Exception e) {
    }
    axis.setLabel("Stunden");
    axis.setAutoRangeIncludesZero(true);
    axis.setLabelPaint(Color.BLACK);
    axis.setTickLabelPaint(Color.BLACK);
    plot.setRangeAxis(0, axis);
    plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);

    plot.setDataset(Linecount, dataset1);
    plot.mapDatasetToRangeAxis(Linecount, 0);

    if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
        renderer = new StandardXYItemRenderer(2, ToolTip);
        renderer.setSeriesPaint(0, getColour(Linecount, 255));

        plot.setRenderer(Linecount, renderer);
    } else {
        rendererb = new XYBarRenderer();
        rendererb.setSeriesPaint(0, getColour(Linecount, 150));
        rendererb.setShadowVisible(false);
        rendererb.setDrawBarOutline(false);
        rendererb.setBarPainter(new StandardXYBarPainter());

        plot.setRenderer(Linecount, rendererb);
    }

    Linecount++;

    dataset = new TimeSeries(
            "Trainingskilometer " + JTronicHandle.Auswahl_bersicht.getSelectedItem().toString());
    for (i = 0; i < 366; i++) {
        dataset.add(xTime[i], y2Werte[i]);

    }

    TimeSeriesCollection dataset2 = new TimeSeriesCollection(dataset);

    NumberAxis axis2 = new NumberAxis();
    try {
        axis2 = (NumberAxis) plot.getRangeAxis().clone();
    } catch (Exception e) {
    }
    ;
    axis2.setLabel("Kilometer");
    axis2.setAutoRangeIncludesZero(true);
    axis2.setLabelPaint(Color.BLACK);
    axis2.setTickLabelPaint(Color.BLACK);

    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    plot.setDataset(Linecount, dataset2);
    plot.mapDatasetToRangeAxis(Linecount, 1);

    if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
        renderer = new StandardXYItemRenderer(2, ToolTip);
        renderer.setSeriesPaint(0, getColour(Linecount, 255));

        plot.setRenderer(Linecount, renderer);
    } else {
        rendererb = new XYBarRenderer();
        rendererb.setSeriesPaint(0, getColour(Linecount, 150));
        rendererb.setShadowVisible(false);
        rendererb.setDrawBarOutline(false);
        rendererb.setBarPainter(new StandardXYBarPainter());

        plot.setRenderer(Linecount, rendererb);
    }

    Linecount++;

    dataset = new TimeSeries(
            "Trainingshhenmeter " + JTronicHandle.Auswahl_bersicht.getSelectedItem().toString());
    for (i = 0; i < 366; i++) {
        dataset.add(xTime[i], y3Werte[i]);

    }

    TimeSeriesCollection dataset3 = new TimeSeriesCollection(dataset);

    NumberAxis axis3 = new NumberAxis("Hhenmeter");
    try {
        axis3 = (NumberAxis) plot.getRangeAxis().clone();
    } catch (Exception e) {
    }
    ;
    axis3.setLabel("Hhenmeter");
    axis3.setAutoRangeIncludesZero(true);
    axis3.setLabelPaint(Color.BLACK);
    axis3.setTickLabelPaint(Color.BLACK);

    plot.setRangeAxis(2, axis3);
    plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(Linecount, dataset3);
    plot.mapDatasetToRangeAxis(Linecount, 2);

    if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
        renderer = new StandardXYItemRenderer(2, ToolTip);
        renderer.setSeriesPaint(0, getColour(Linecount, 255));

        plot.setRenderer(Linecount, renderer);
    } else {
        rendererb = new XYBarRenderer();
        rendererb.setSeriesPaint(0, getColour(Linecount, 150));
        rendererb.setShadowVisible(false);
        rendererb.setDrawBarOutline(false);
        rendererb.setBarPainter(new StandardXYBarPainter());

        plot.setRenderer(Linecount, rendererb);
    }

    Linecount++;

    if (Vergleich == true) {
        SummeZeit = 0;
        Summekm = 0;
        Summehm = 0;

        SummeZeit12Mon = 0;
        Summekm12Mon = 0;
        Summehm12Mon = 0;

        for (i = 0; i < 366; i++) {
            SummeZeit12Mon += (double) Zeit[SelektiertVergl - 1][i];
            Summekm12Mon += (double) kmJahr[SelektiertVergl - 1][i];
            Summehm12Mon += (double) HmJahr[SelektiertVergl - 1][i];
        }

        y4Werte[0] = SummeZeit12Mon;
        y5Werte[0] = Summekm12Mon;
        y6Werte[0] = Summehm12Mon;

        for (i = 1; i < 366; i++) {
            try {

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Exception GregorianCalender  " + e, "Achtung!",
                        JOptionPane.ERROR_MESSAGE);
            }
            ;
            if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
                SummeZeit += (double) Zeit[SelektiertVergl - 1][i];
                Summekm += (double) kmJahr[SelektiertVergl - 1][i];
                Summehm += (double) HmJahr[SelektiertVergl - 1][i];
                y7Werte[i] = SummeZeit;
                y8Werte[i] = Summekm;
                y9Werte[i] = Summehm;

                y4Werte[i] = y4Werte[i - 1] - (double) Zeit[SelektiertVergl - 1][i]
                        + (double) Zeit[Selektiert][i];
                y5Werte[i] = y5Werte[i - 1] - (double) kmJahr[SelektiertVergl - 1][i]
                        + (double) kmJahr[Selektiert][i];
                y6Werte[i] = y6Werte[i - 1] - (double) HmJahr[SelektiertVergl - 1][i]
                        + (double) HmJahr[Selektiert][i];
            } else {
                Day n = new Day(1, xTime[i].getMonth(), xTime[i].getYear());
                try {
                    Kalender = new GregorianCalendar(xTime[i].getYear(), xTime[i].getMonth() - 1, 1);

                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Exception GregorianCalender  " + e, "Achtung!",
                            JOptionPane.ERROR_MESSAGE);

                }
                int j = (int) Kalender.get(Kalender.DAY_OF_YEAR);
                for (int m = 0; m < 5; m++) {
                    y7Werte[j + m + 4] += (double) Zeit[SelektiertVergl - 1][i];
                    y8Werte[j + m + 14] += (double) kmJahr[SelektiertVergl - 1][i];
                    y9Werte[j + m + 24] += (double) HmJahr[SelektiertVergl - 1][i];

                }

            }

        }

        if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
            dataset = new TimeSeries("Trainingszeit ber 12 Monate ");
            for (i = 0; i < 366; i++) {
                dataset.add(xTime[i], y4Werte[i]);
            }

            TimeSeriesCollection dataset4 = new TimeSeriesCollection(dataset);

            plot.setDataset(Linecount, dataset4);
            plot.mapDatasetToRangeAxis(Linecount, 0);

            if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
                renderer = new StandardXYItemRenderer(2, ToolTip);
                renderer.setSeriesPaint(0, getColour(Linecount, 255));

                plot.setRenderer(Linecount, renderer);
            } else {
                rendererb = new XYBarRenderer();
                rendererb.setSeriesPaint(0, getColour(Linecount, 150));
                rendererb.setShadowVisible(false);
                rendererb.setBarPainter(new StandardXYBarPainter());

                plot.setRenderer(Linecount, rendererb);
            }

            Linecount++;

            dataset = new TimeSeries("Trainingskilometer ber 12 Monate ");
            for (i = 0; i < 366; i++) {
                dataset.add(xTime[i], y5Werte[i]);
            }

            TimeSeriesCollection dataset5 = new TimeSeriesCollection(dataset);

            plot.setDataset(Linecount, dataset5);
            plot.mapDatasetToRangeAxis(Linecount, 1);

            if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
                renderer = new StandardXYItemRenderer(2, ToolTip);
                renderer.setSeriesPaint(0, getColour(Linecount, 255));

                plot.setRenderer(Linecount, renderer);
            } else {
                rendererb = new XYBarRenderer();
                rendererb.setSeriesPaint(0, getColour(Linecount, 150));
                rendererb.setShadowVisible(false);
                rendererb.setGradientPaintTransformer(null);
                rendererb.setBarPainter(new StandardXYBarPainter());

                plot.setRenderer(Linecount, rendererb);
            }

            Linecount++;

            dataset = new TimeSeries("Trainingshhenmeter ber 12 Monate ");
            for (i = 0; i < 366; i++) {
                dataset.add(xTime[i], y6Werte[i]);
            }

            TimeSeriesCollection dataset6 = new TimeSeriesCollection(dataset);

            plot.setDataset(Linecount, dataset6);
            plot.mapDatasetToRangeAxis(Linecount, 2);

            if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
                renderer = new StandardXYItemRenderer(2, ToolTip);
                renderer.setSeriesPaint(0, getColour(Linecount, 255));

                plot.setRenderer(Linecount, renderer);
            } else {
                rendererb = new XYBarRenderer();
                rendererb.setSeriesPaint(0, getColour(Linecount, 150));
                rendererb.setShadowVisible(false);
                rendererb.setGradientPaintTransformer(null);
                rendererb.setBarPainter(new StandardXYBarPainter());

                plot.setRenderer(Linecount, rendererb);
            }

        }
        Linecount++;

        dataset = new TimeSeries("Trainingszeit " + JTronicHandle.JahrVergleich.getSelectedItem().toString());
        for (i = 0; i < 366; i++) {
            dataset.add(xTime[i], y7Werte[i]);
        }

        TimeSeriesCollection dataset7 = new TimeSeriesCollection(dataset);

        plot.setDataset(Linecount, dataset7);
        plot.mapDatasetToRangeAxis(Linecount, 0);

        if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
            renderer = new StandardXYItemRenderer(2, ToolTip);
            renderer.setSeriesPaint(0, getColour(Linecount, 255));

            plot.setRenderer(Linecount, renderer);
        } else {
            rendererb = new XYBarRenderer();
            rendererb.setSeriesPaint(0, getColour(Linecount, 150));
            rendererb.setShadowVisible(false);
            rendererb.setGradientPaintTransformer(null);
            rendererb.setBarPainter(new StandardXYBarPainter());

            plot.setRenderer(Linecount, rendererb);
        }
        Linecount++;

        dataset = new TimeSeries(
                "Trainingskilometer " + JTronicHandle.JahrVergleich.getSelectedItem().toString());
        for (i = 0; i < 366; i++) {
            dataset.add(xTime[i], y8Werte[i]);
        }

        TimeSeriesCollection dataset8 = new TimeSeriesCollection(dataset);

        plot.setDataset(Linecount, dataset8);
        plot.mapDatasetToRangeAxis(Linecount, 1);

        if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
            renderer = new StandardXYItemRenderer(2, ToolTip);
            renderer.setSeriesPaint(0, getColour(Linecount, 255));

            plot.setRenderer(Linecount, renderer);
        } else {
            rendererb = new XYBarRenderer();
            rendererb.setSeriesPaint(0, getColour(Linecount, 150));
            rendererb.setShadowVisible(false);
            rendererb.setGradientPaintTransformer(null);
            rendererb.setBarPainter(new StandardXYBarPainter());

            plot.setRenderer(Linecount, rendererb);
        }

        Linecount++;

        dataset = new TimeSeries(
                "Trainingshhenmeter " + JTronicHandle.JahrVergleich.getSelectedItem().toString());
        for (i = 0; i < 366; i++) {
            dataset.add(xTime[i], y9Werte[i]);
        }

        TimeSeriesCollection dataset9 = new TimeSeriesCollection(dataset);

        plot.setDataset(Linecount, dataset9);
        plot.mapDatasetToRangeAxis(Linecount, 2);

        if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
            renderer = new StandardXYItemRenderer(2, ToolTip);
            renderer.setSeriesPaint(0, getColour(Linecount, 255));

            plot.setRenderer(Linecount, renderer);
        } else {
            rendererb = new XYBarRenderer();
            rendererb.setSeriesPaint(0, getColour(Linecount, 150));
            rendererb.setShadowVisible(false);
            rendererb.setGradientPaintTransformer(null);
            rendererb.setBarPainter(new StandardXYBarPainter());

            plot.setRenderer(Linecount, rendererb);
        }

    }

    if (!JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {

        double max = axis.getRange().getUpperBound();
        for (i = 0; i < 12; i++) {
            try {
                Kalender = new GregorianCalendar(Integer.parseInt(DataProperty.getProperty("Jahr", "0")), i, 1);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "JUebersicht\nException GregorianCalender  " + e,
                        "Achtung!", JOptionPane.ERROR_MESSAGE);
            }

            y10Werte[Kalender.get(Kalender.DAY_OF_YEAR)] = max;
            y10Werte[Kalender.get(Kalender.DAY_OF_YEAR) + 1] = 0;
        }
        dataset = new TimeSeries("");

        for (i = 0; i < 366; i++) {

            dataset.add(xTime[i], y10Werte[i]);

        }
        TimeSeriesCollection dataset10 = new TimeSeriesCollection(dataset);
        plot.setDataset(Linecount + 1, dataset10);
        plot.mapDatasetToRangeAxis(Linecount + 1, 0);

        renderer = new StandardXYItemRenderer(2, ToolTip);
        renderer.setSeriesPaint(0, Color.white);

        plot.setRenderer(Linecount + 1, renderer);
        plot.getDomainAxis().setAutoRange(false);
        axis.setRange(0, max);

    }

    if (JTronicHandle.jRadioButton_jahresverlauf.isSelected()) {
        axis2.setRange(0, axis2.getRange().getUpperBound() * 1.5);
        axis3.setRange(0, axis3.getRange().getUpperBound() * 2);
        plot.setDomainCrosshairValue(
                (double) new GregorianCalendar(Jahr, Today.get(Today.MONTH), Today.get(Today.DAY_OF_MONTH))
                        .getTimeInMillis());

    }

    chart.setPadding(padding);
    ChartPanel Panel = new ChartPanel(chart);
    Panel.setDismissDelay(100000);

    return Panel;

}

From source file:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java

private JFreeChart createChart() {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*from w  w w . j a  v  a  2s . com*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
        if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            chart.getXYPlot().setDomainAxis(domainAxis);
        }
    } else {
        plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) {
        xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    } else {
        xAxis.setLabel(SERIESINDEX_LABEL);
    }
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
        if (getRangeForDimension(indexAxis) != null) {
            xAxis.setRange(getRangeForDimension(indexAxis));
        }
    } else {
        if (getRangeForName(SERIESINDEX_LABEL) != null) {
            xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
        }
    }

    // renderer and range axis
    synchronized (dataTable) {
        int numberOfSelectedColumns = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    numberOfSelectedColumns++;
                }
            }
        }

        int columnCount = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    // YIntervalSeries series = new
                    // YIntervalSeries(this.dataTable.getColumnName(c));
                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries(dataTable.getColumnName(c));
                    Iterator<DataTableRow> i = dataTable.iterator();
                    int index = 1;
                    while (i.hasNext()) {
                        DataTableRow row = i.next();
                        double value = row.getValue(c);

                        if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                            double indexValue = row.getValue(indexAxis);
                            series.add(indexValue, value);
                        } else {
                            series.add(index++, value);
                        }
                    }
                    dataset.addSeries(series);

                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

                    Color color = getColorProvider().getPointColor(1.0d);
                    if (numberOfSelectedColumns > 1) {
                        color = getColorProvider()
                                .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
                    }
                    renderer.setSeriesPaint(0, color);
                    renderer.setSeriesStroke(0,
                            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                    renderer.setSeriesShapesVisible(0, false);

                    NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
                    if (getRangeForDimension(c) != null) {
                        yAxis.setRange(getRangeForDimension(c));
                    } else {
                        yAxis.setAutoRange(true);
                        yAxis.setAutoRangeStickyZero(false);
                        yAxis.setAutoRangeIncludesZero(false);
                    }
                    yAxis.setLabelFont(LABEL_FONT_BOLD);
                    yAxis.setTickLabelFont(LABEL_FONT);
                    if (numberOfSelectedColumns > 1) {
                        yAxis.setAxisLinePaint(color);
                        yAxis.setTickMarkPaint(color);
                        yAxis.setLabelPaint(color);
                        yAxis.setTickLabelPaint(color);
                    }

                    plot.setRangeAxis(columnCount, yAxis);
                    plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

                    plot.setDataset(columnCount, dataset);
                    plot.setRenderer(columnCount, renderer);
                    plot.mapDatasetToRangeAxis(columnCount, columnCount);

                    columnCount++;
                }
            }
        }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:org.ramadda.geodata.cdmdata.PointDatabaseTypeHandler.java

/**
 * _more_/*  ww  w .j  ava2s.  c o m*/
 *
 * @param request _more_
 * @param entry _more_
 * @param columnsToUse _more_
 * @param list _more_
 *
 * @return _more_
 *
 * @throws Exception _more_
 */
private Result makeSearchResultsTimeSeries(Request request, Entry entry, List<PointDataMetadata> columnsToUse,
        List<PointData> list) throws Exception {

    StringBuffer sb = new StringBuffer();
    sb.append(getHeader(request, entry));
    sb.append(header(msg("Point Data Search Results")));
    if (list.size() == 0) {
        sb.append(msg("No results found"));

        return new Result("Point Search Results", sb);
    }

    TimeSeriesCollection dummy = new TimeSeriesCollection();
    JFreeChart chart = createChart(request, entry, dummy);
    XYPlot xyPlot = (XYPlot) chart.getPlot();

    Hashtable<String, MyTimeSeries> seriesMap = new Hashtable<String, MyTimeSeries>();
    List<MyTimeSeries> allSeries = new ArrayList<MyTimeSeries>();
    int paramCount = 0;
    int colorCount = 0;
    boolean axisLeft = true;
    Hashtable<String, List<ValueAxis>> axisMap = new Hashtable<String, List<ValueAxis>>();
    Hashtable<String, double[]> rangeMap = new Hashtable<String, double[]>();
    List<String> units = new ArrayList<String>();

    long t1 = System.currentTimeMillis();

    for (PointData pointData : list) {
        for (PointDataMetadata pdm : columnsToUse) {
            if (!pdm.isNumeric()) {
                continue;
            }
            double value = ((Double) pointData.getValue(pdm)).doubleValue();
            if (value != value) {
                continue;
            }
            List<ValueAxis> axises = null;
            double[] range = null;
            if (pdm.hasUnit()) {
                axises = axisMap.get(pdm.unit);
                range = rangeMap.get(pdm.unit);
                if (axises == null) {
                    axises = new ArrayList<ValueAxis>();
                    range = new double[] { value, value };
                    rangeMap.put(pdm.unit, range);
                    axisMap.put(pdm.unit, axises);
                    units.add(pdm.unit);
                }
                range[0] = Math.min(range[0], value);
                range[1] = Math.max(range[1], value);
            }
            MyTimeSeries series = seriesMap.get(pdm.getColumnName());
            if (series == null) {
                paramCount++;
                TimeSeriesCollection dataset = new TimeSeriesCollection();
                series = new MyTimeSeries(pdm.formatName(), FixedMillisecond.class);
                allSeries.add(series);
                ValueAxis rangeAxis = new NumberAxis(pdm.formatName() + " " + pdm.formatUnit());
                if (axises != null) {
                    axises.add(rangeAxis);
                }
                XYItemRenderer renderer = new XYAreaRenderer(XYAreaRenderer.LINES);
                if (colorCount >= HtmlUtils.COLORS.length) {
                    colorCount = 0;
                }
                renderer.setSeriesPaint(0, HtmlUtils.COLORS[colorCount]);
                colorCount++;
                xyPlot.setRenderer(paramCount, renderer);
                xyPlot.setRangeAxis(paramCount, rangeAxis, false);
                AxisLocation side = (axisLeft ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT);
                axisLeft = !axisLeft;
                xyPlot.setRangeAxisLocation(paramCount, side);

                dataset.setDomainIsPointsInTime(true);
                dataset.addSeries(series);
                seriesMap.put(pdm.getColumnName(), series);
                xyPlot.setDataset(paramCount, dataset);
                xyPlot.mapDatasetToRangeAxis(paramCount, paramCount);
            }
            //series.addOrUpdate(new FixedMillisecond(pointData.date),value);
            TimeSeriesDataItem item = new TimeSeriesDataItem(new FixedMillisecond(pointData.date), value);
            series.addItem(item);
        }
    }

    for (MyTimeSeries timeSeries : allSeries) {
        timeSeries.finish();
    }

    for (String unit : units) {
        List<ValueAxis> axises = axisMap.get(unit);
        double[] range = rangeMap.get(unit);
        for (ValueAxis rangeAxis : axises) {
            rangeAxis.setRange(new org.jfree.data.Range(range[0], range[1]));
        }
    }

    long t2 = System.currentTimeMillis();

    BufferedImage newImage = chart.createBufferedImage(request.get(ARG_POINT_IMAGE_WIDTH, 1000),
            request.get(ARG_POINT_IMAGE_HEIGHT, 400));
    long t3 = System.currentTimeMillis();
    //System.err.println("timeseries image time:" + (t2 - t1) + " "
    //                   + (t3 - t2));

    File file = getStorageManager().getTmpFile(request, "point.png");
    ImageUtils.writeImageToFile(newImage, file);
    InputStream is = getStorageManager().getFileInputStream(file);
    Result result = new Result("", is, "image/png");

    return result;

}