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

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

Introduction

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

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

Sets a dataset for the plot and sends a change event to all registered listeners.

Usage

From source file:mil.tatrc.physiology.utilities.csv.plots.ConvexHullPlotter.java

public void plot(LogListener listener, SESubstanceManager subMgr) {
    //fill PlotJob with needed data if it doesn't exist
    PlotJob job = (PlotJob) listener;/*  w  w w.  j  a v a  2 s . co m*/
    if (job.dataPath == null || job.dataPath.isEmpty()) {
        job.dataPath = "../verification/Scenarios/" + job.verificationDirectory + "/Current Baseline/";
    }
    if (job.dataFile == null || job.dataFile.isEmpty()) {
        job.dataFile = job.name + "Results.zip";
    }

    //Get data contents for all headers
    if (data.isEmpty() || data == null) {
        try {
            CSVContents csv = new CSVContents(job.dataPath + job.dataFile);
            csv.abbreviateContents = job.resultsSkipNum;
            for (int i = 0; i < job.headers.size(); i++) {
                List<Double> headerData = new ArrayList<Double>();
                csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData);
                data.put(job.headers.get(i), headerData);
            }
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.dataPath + job.dataFile);
        }
    }

    //Catch some errors
    if (job.Y2headers.size() > 0 && job.X2header == null) {
        Log.error("No X2 header specified for job " + job.name
                + ". Each Y axis must have a corresponding X axis.");
        return;
    }

    //Make a dataSeries for desired headers and add to collection(s)
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet1 = new XYSeriesCollection();
    XYSeriesCollection dataSet2 = new XYSeriesCollection();
    double maxY1 = 0;
    double minY1 = Double.MAX_VALUE;
    double maxY2 = 0;
    double minY2 = Double.MAX_VALUE;
    for (int i = 0; i < job.Y1headers.size(); i++) {
        XYSeries dataSeriesTop;
        XYSeries dataSeriesBottom;
        XYSeries dataSeriesLeft;
        XYSeries dataSeriesRight;

        //For convex hulls, we have to reorder points before inserting into the dataset
        ConvexHullMaker maker = new ConvexHullMaker();
        List<List<Double>> newVals = new ArrayList<List<Double>>();
        List<List<Double>> splitVals = new ArrayList<List<Double>>();
        newVals = maker.make(data.get(job.X1header), data.get(job.Y1headers.get(i)));
        splitVals = splitHull(newVals);
        dataSeriesTop = plotTool.createXYSeries(job.Y1headers.get(i), splitVals.get(0), splitVals.get(1));
        dataSeriesBottom = plotTool.createXYSeries("", splitVals.get(2), splitVals.get(3));
        dataSeriesLeft = plotTool.createXYSeries("", splitVals.get(4), splitVals.get(5));
        dataSeriesRight = plotTool.createXYSeries("", splitVals.get(6), splitVals.get(7));

        dataSeriesBottom.setKey("REMOVE");
        dataSeriesLeft.setKey("REMOVE");
        dataSeriesRight.setKey("REMOVE");

        dataSet1.addSeries(dataSeriesTop);
        dataSet1.addSeries(dataSeriesBottom);
        dataSet1.addSeries(dataSeriesLeft);
        dataSet1.addSeries(dataSeriesRight);

        title = title + job.Y1headers.get(i) + "_";
        maxY1 = maxY1 < dataSeriesTop.getMaxY() ? dataSeriesTop.getMaxY() : maxY1;
        minY1 = minY1 > dataSeriesBottom.getMinY() ? dataSeriesBottom.getMinY() : minY1;
    }
    for (int i = 0; i < job.Y2headers.size(); i++) {
        XYSeries dataSeriesTop;
        XYSeries dataSeriesBottom;
        XYSeries dataSeriesLeft;
        XYSeries dataSeriesRight;

        ConvexHullMaker maker = new ConvexHullMaker();
        List<List<Double>> newVals = new ArrayList<List<Double>>();
        List<List<Double>> splitVals = new ArrayList<List<Double>>();
        newVals = maker.make(data.get(job.X2header), data.get(job.Y2headers.get(i)));
        splitVals = splitHull(newVals);
        dataSeriesTop = plotTool.createXYSeries(job.Y2headers.get(i), splitVals.get(0), splitVals.get(1));
        dataSeriesBottom = plotTool.createXYSeries("", splitVals.get(2), splitVals.get(3));
        dataSeriesLeft = plotTool.createXYSeries("", splitVals.get(4), splitVals.get(5));
        dataSeriesRight = plotTool.createXYSeries("", splitVals.get(6), splitVals.get(7));

        dataSeriesBottom.setKey("REMOVE");
        dataSeriesLeft.setKey("REMOVE");
        dataSeriesRight.setKey("REMOVE");

        dataSet2.addSeries(dataSeriesTop);
        dataSet2.addSeries(dataSeriesBottom);
        dataSet2.addSeries(dataSeriesLeft);
        dataSet2.addSeries(dataSeriesRight);

        title = title + job.Y2headers.get(i) + "_";
        maxY2 = maxY2 < dataSeriesTop.getMaxY() ? dataSeriesTop.getMaxY() : maxY2;
        minY2 = minY2 > dataSeriesBottom.getMinY() ? dataSeriesBottom.getMinY() : minY2;
    }
    title = title + "vs_" + job.X1header;
    if (job.X2header != null && !job.X1header.equalsIgnoreCase(job.X2header))
        title = title + "_" + job.X2header;

    //Override the constructed title if desired
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    //set labels
    String XAxisLabel = job.X1header;
    String YAxisLabel = job.Y1headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet1, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y1 range
        double resMax0 = maxY1;
        double resMin0 = minY1;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis(0).setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.001;
        double rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis(0);
        yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly  

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        //Add the second Y axis to the right side
        if (!job.Y2headers.isEmpty()) {
            ValueAxis rightYAxis = new NumberAxis();
            // Determine Y2 range
            double resMax1 = maxY2;
            double resMin1 = minY2;
            if (Double.isNaN(resMax1) || Double.isNaN(resMin1))
                plot.getDomainAxis(1).setLabel("Range is NaN");
            if (DoubleUtils.isZero(resMin1))
                resMin1 = -0.001;
            if (DoubleUtils.isZero(resMax1))
                resMax1 = 0.001;
            rangeLength = resMax1 - resMin1;
            rightYAxis.setRange(resMin1 - 0.15 * rangeLength, resMax1 + 0.15 * rangeLength);
            rightYAxis.setLabel(job.Y2headers.get(0));

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    } else {
        double resMin = minY1 < minY2 ? minY1 : minY2;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        yAxis.setLowerBound(resMin);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        if (!job.Y2headers.isEmpty()) {
            LogarithmicAxis rightYAxis = new LogarithmicAxis("Log(" + job.Y2headers.get(0) + ")");
            rightYAxis.setLowerBound(resMin);

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
        if (job.X2LowerBound != null)
            plot.getDomainAxis(1).setLowerBound(job.X2LowerBound);
        if (job.X2UpperBound != null)
            plot.getDomainAxis(1).setUpperBound(job.X2UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Add the second dataset if necessary
    if (!job.Y2headers.isEmpty()) {
        plot.setDataset(1, dataSet2);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.X2Label != null && plot.getDomainAxis(1) != null)
        plot.getDomainAxis(1).setLabel(job.X2Label.equalsIgnoreCase("None") ? "" : job.X2Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);
    if (job.Y2Label != null && plot.getRangeAxis(1) != null)
        plot.getRangeAxis(1).setLabel(job.Y2Label.equalsIgnoreCase("None") ? "" : job.Y2Label);

    //Format lines and colors
    plotTool.formatXYPlot(chart, job.bgColor);
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);
    formatConvexHullPlot(job, chart, dataSet1, dataSet2);

    //Handle legends
    if (job.removeAllLegends)
        chart.removeLegend();

    //Make the file
    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }

}

From source file:mil.tatrc.physiology.utilities.csv.plots.MultiPlotter.java

@Override
public void plot(LogListener listener, SESubstanceManager subMgr) {
    //fill PlotJob with needed data if it doesn't exist
    PlotJob job = (PlotJob) listener;//from w  ww  .j a  va 2 s .  c  o  m
    if (job.dataPath == null || job.dataPath.isEmpty()) {
        job.dataPath = "../verification/Scenarios/" + job.verificationDirectory + "/Current Baseline/";
    }
    if (job.dataFile == null || job.dataFile.isEmpty()) {
        job.dataFile = job.name + "Results.zip";
    }

    //Get data contents for all headers when all data is in one file
    if ((data.isEmpty() || data == null) && job.experimentalData == null) {
        try {
            CSVContents csv = new CSVContents(job.dataPath + job.dataFile);
            csv.abbreviateContents = job.resultsSkipNum;
            for (int i = 0; i < job.headers.size(); i++) {
                List<Double> headerData = new ArrayList<Double>();
                csv.readHeader(csv.unitUnderscoreToSpace(job.headers.get(i)), headerData);
                data.put(job.headers.get(i), headerData);
            }
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.dataPath + job.dataFile);
        }
    }
    //Get data contents when we're also using experimental files
    else if ((data.isEmpty() || data == null) && job.experimentalData != null) {
        CSVContents dataCsv = null;
        CSVContents expCsv = null;

        try {
            dataCsv = new CSVContents(job.dataPath + job.dataFile);
            dataCsv.abbreviateContents = job.resultsSkipNum;
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.dataPath + job.dataFile);
        }
        try {
            expCsv = new CSVContents(job.experimentalData);
            expCsv.abbreviateContents = 0; //we'll use all of the experimental data
        } catch (IOException e) {
            Log.error("Could not analyze file " + job.experimentalData);
        }
        try {
            //Get data from X1 and Y1, which should always be from our normal data file
            for (int i = 0; i < job.Y1headers.size(); i++) {
                List<Double> headerData = new ArrayList<Double>();
                dataCsv.readHeader(dataCsv.unitUnderscoreToSpace(job.Y1headers.get(i)), headerData);
                data.put(job.Y1headers.get(i), headerData);
            }
            List<Double> headerData = new ArrayList<Double>();
            dataCsv.readHeader(dataCsv.unitUnderscoreToSpace(job.X1header), headerData);
            data.put(job.X1header, headerData);

            for (int i = 0; i < job.Y2headers.size(); i++) {
                List<Double> headerData2 = new ArrayList<Double>();
                expCsv.readHeader(expCsv.unitUnderscoreToSpace(job.Y2headers.get(i)), headerData2);
                expData.put(job.Y2headers.get(i), headerData2);
            }
            List<Double> headerData2 = new ArrayList<Double>();
            expCsv.readHeader(expCsv.unitUnderscoreToSpace(job.X2header), headerData2);
            expData.put(job.X2header, headerData2);
        } catch (Exception e) {
            Log.error("A problem was encountered reading headers from files.");
        }
    }

    //Catch some errors
    if (job.Y2headers.size() > 0 && job.X2header == null) {
        Log.error("No X2 header specified for job " + job.name
                + ". Each Y axis must have a corresponding X axis.");
        return;
    }

    //Make a dataSeries for desired headers and add to collection(s)
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet1 = new XYSeriesCollection();
    XYSeriesCollection dataSet2 = new XYSeriesCollection();
    double maxY1 = 0;
    double minY1 = Double.MAX_VALUE;
    double maxY2 = 0;
    double minY2 = Double.MAX_VALUE;
    for (int i = 0; i < job.Y1headers.size(); i++) {
        XYSeries dataSeries;
        if (job.experimentalData != null)
            dataSeries = plotTool.createXYSeries("BioGears " + job.Y1headers.get(i), data.get(job.X1header),
                    data.get(job.Y1headers.get(i)));
        else
            dataSeries = plotTool.createXYSeries(job.Y1headers.get(i), data.get(job.X1header),
                    data.get(job.Y1headers.get(i)));
        dataSet1.addSeries(dataSeries);
        title = title + job.Y1headers.get(i) + "_";
        maxY1 = maxY1 < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY1;
        minY1 = minY1 > dataSeries.getMinY() ? dataSeries.getMinY() : minY1;
    }
    for (int i = 0; i < job.Y2headers.size(); i++) {
        XYSeries dataSeries;
        if (job.experimentalData != null)
            dataSeries = plotTool.createXYSeries("Experimental " + job.Y2headers.get(i),
                    expData.get(job.X2header), expData.get(job.Y2headers.get(i)));
        else
            dataSeries = plotTool.createXYSeries(job.Y2headers.get(i), data.get(job.X2header),
                    data.get(job.Y2headers.get(i)));
        dataSet2.addSeries(dataSeries);
        title = title + job.Y2headers.get(i) + "_";
        maxY2 = maxY2 < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY2;
        minY2 = minY2 > dataSeries.getMinY() ? dataSeries.getMinY() : minY2;
    }
    title = title + "vs_" + job.X1header;
    if (job.X2header != null && !job.X1header.equalsIgnoreCase(job.X2header))
        title = title + "_" + job.X2header;

    //Override the constructed title if desired
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    //set labels
    String XAxisLabel = job.X1header;
    String YAxisLabel = job.Y1headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet1, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y1 range
        double resMax0 = maxY1;
        double resMin0 = minY1;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis(0).setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.001;
        double rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis(0);
        if (rangeLength != 0)
            yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly  

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        //Add the second Y axis to the right side
        if (!job.Y2headers.isEmpty()) {
            ValueAxis rightYAxis = new NumberAxis();
            // Determine Y2 range
            double resMax1 = maxY2;
            double resMin1 = minY2;
            if (Double.isNaN(resMax1) || Double.isNaN(resMin1))
                plot.getDomainAxis(1).setLabel("Range is NaN");
            if (DoubleUtils.isZero(resMin1))
                resMin1 = -0.001;
            if (DoubleUtils.isZero(resMax1))
                resMax1 = 0.001;
            rangeLength = resMax1 - resMin1;
            if (rangeLength != 0)
                rightYAxis.setRange(resMin1 - 0.15 * rangeLength, resMax1 + 0.15 * rangeLength);
            rightYAxis.setLabel(job.Y2headers.get(0));

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    } else {
        double resMin = minY1 < minY2 ? minY1 : minY2;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        yAxis.setLowerBound(resMin);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null)
                yAxis.setLowerBound(job.Y1LowerBound);
            if (job.Y1UpperBound != null)
                yAxis.setUpperBound(job.Y1UpperBound);
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }

        plot.setRangeAxis(0, yAxis);

        if (!job.Y2headers.isEmpty()) {
            LogarithmicAxis rightYAxis = new LogarithmicAxis("Log(" + job.Y2headers.get(0) + ")");
            rightYAxis.setLowerBound(resMin);

            //Override the bounds if desired
            try {
                if (job.Y2LowerBound != null)
                    rightYAxis.setLowerBound(job.Y2LowerBound);
                if (job.Y2UpperBound != null)
                    rightYAxis.setUpperBound(job.Y2UpperBound);
            } catch (Exception e) {
                Log.error(
                        "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
            }

            plot.setRangeAxis(1, rightYAxis);
        }
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
        if (job.X2LowerBound != null)
            plot.getDomainAxis(1).setLowerBound(job.X2LowerBound);
        if (job.X2UpperBound != null)
            plot.getDomainAxis(1).setUpperBound(job.X2UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Add the second dataset if necessary
    if (!job.Y2headers.isEmpty()) {
        plot.setDataset(1, dataSet2);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.X2Label != null && plot.getDomainAxis(1) != null)
        plot.getDomainAxis(1).setLabel(job.X2Label.equalsIgnoreCase("None") ? "" : job.X2Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);
    if (job.Y2Label != null && plot.getRangeAxis(1) != null)
        plot.getRangeAxis(1).setLabel(job.Y2Label.equalsIgnoreCase("None") ? "" : job.Y2Label);

    //Format lines and colors
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);
    formatMultiPlot(job, chart, dataSet1, dataSet2);

    //Handle legends
    if (job.removeAllLegends)
        chart.removeLegend();

    //Make the file
    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }

}

From source file:com.att.aro.ui.view.diagnostictab.plot.VideoChunksPlot.java

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    if (analysis != null) {
        VideoUsage videousage = analysis.getAnalyzerResult().getVideoUsage();
        if (!isReDraw) {
            boPlot.clearPlot(this.bufferOccupancyPlot);
            boTimePlot.clearPlot(this.bufferTimePlot);
            analysis.getAnalyzerResult().setBufferTimeResult(null);
            analysis.getAnalyzerResult().setBufferOccupancyResult(null);
        }//from   w w  w .j  a  v a 2s.c  o m

        videoChunksData.removeAllSeries();
        for (XYSeriesCollection seriesColl : startUpDelayCollection) {
            seriesColl.removeAllSeries();
        }

        startUpDelayCollection.clear();
        imgSeries = new ArrayList<BufferedImage>();

        // create the dataset...
        int index = 0;

        series = new XYSeries("Chunks");
        seriesDataSets = new TreeMap<>();
        seriesDataSets = videoChunkPlotter.populateDataSet(analysis.getAnalyzerResult().getVideoUsage());

        imgSeries = videoChunkPlotter.getImageSeries();
        filteredChunks = videousage.getFilteredSegments();
        segmentsToBePlayed.clear();
        if (videousage.getAllSegments() != null) {
            for (VideoEvent ve : videousage.getAllSegments()) {
                segmentsToBePlayed.add(ve);
            }
        }
        for (double timeStamp : seriesDataSets.values()) {
            series.add(timeStamp, 0);
        }

        XYSeriesCollection playTimeStartSeries;
        int first = 0;

        List<VideoEvent> chunkPlayBackTimeList = new ArrayList<VideoEvent>(chunkPlayTime.keySet());
        Collections.sort(chunkPlayBackTimeList, new VideoEventComparator(SortSelection.SEGMENT));
        for (VideoEvent ve : chunkPlayBackTimeList) {

            playTimeStartSeries = new XYSeriesCollection();

            seriesStartUpDelay = new XYSeries("StartUpDelay" + (index++));
            seriesStartUpDelay.add(ve.getDLTimeStamp(), 0);
            seriesStartUpDelay.add((double) chunkPlayTime.get(ve), 0);

            if (first == 0) {
                VideoUsage videoUsage = analysis.getAnalyzerResult().getVideoUsage();
                TreeMap<Double, AROManifest> videoEventList = videoUsage.getAroManifestMap();

                setDelayAROManifest((double) chunkPlayTime.get(ve) - ve.getEndTS(), videoEventList.values());//Set start up delay in AROManifest getDLTimeStamp()

            }
            playTimeStartSeries.addSeries(seriesStartUpDelay);

            startUpDelayCollection.add(playTimeStartSeries);
            first++;
        }

        videoChunksData.addSeries(series);

        VideoChunckImageRenderer renderer = new VideoChunckImageRenderer();
        XYLineAndShapeRenderer rendererDelay = new XYLineAndShapeRenderer();
        for (int i = 0; i < startUpDelayCollection.size(); i++) {
            rendererDelay.setSeriesStroke(i, new BasicStroke(1.0f));
            rendererDelay.setSeriesPaint(i, Color.red);
        }

        XYToolTipGenerator xyToolTipGenerator = new XYToolTipGenerator() {
            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {
                StringBuffer tooltipValue = new StringBuffer();
                VideoEvent currentVEvent = segmentsToBePlayed.get(item);

                DecimalFormat decimalFormat = new DecimalFormat("0.##");

                tooltipValue.append(decimalFormat.format(currentVEvent.getSegment()) + ","
                        + String.format("%.2f", currentVEvent.getStartTS()) + ","
                        + String.format("%.2f", currentVEvent.getEndTS()) + ",");

                if (!chunkPlayTime.isEmpty()) {
                    if (videoChunkPlotter.getSegmentPlayStartTime(currentVEvent) == -1) {
                        tooltipValue.append("- ,");
                    } else {
                        tooltipValue.append(
                                String.format("%.2f", videoChunkPlotter.getSegmentPlayStartTime(currentVEvent))
                                        + " s,");
                    }
                } else {
                    tooltipValue.append("- ,");
                }
                tooltipValue.append(currentVEvent.getTotalBytes() / 1000); //Converting to KB
                String[] value = tooltipValue.toString().split(",");
                return (MessageFormat.format(VIDEOCHUNK_TOOLTIP, value[0], value[1], value[2], value[3],
                        value[4]));

            }

        };

        renderer.setBaseToolTipGenerator(xyToolTipGenerator);
        renderer.setSeriesShape(0, shape);

        plot.setRenderer(index, renderer);
        for (int i = 0; i < startUpDelayCollection.size(); i++)
            plot.setRenderer(i, rendererDelay);
    }
    isReDraw = false;
    int seriesIndex = 0;
    for (XYSeriesCollection seriesColl : startUpDelayCollection) {
        plot.setDataset(seriesIndex, seriesColl);
        seriesIndex++;
    }

    plot.setDataset(seriesIndex, videoChunksData);
}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart.// www. j  av  a2 s.c  om
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}

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

/**
 * _more_/*from  w ww.j  a  v a2s.  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;

}

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

/**
 * Output the timeseries image/*from   w  ww  .j  a v  a  2s  .  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 >= GuiUtils.COLORS.length) {
                    colorCount = 0;
                }
                renderer.setSeriesPaint(0, GuiUtils.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:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java

/**
 * Creates a chart.//from w w w  .j a v a 2  s . co m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
// protected JFreeChart createChart(XYDataset dataset, double[][] polygons, int num_poly) {

protected JFreeChart createChart(XYDataset[] dataset) {
    //System.out.println("createChart get called");
    boolean legend = false;
    /*if (num_series>1&&segment_flag==false)
       legend = true;*/

    //   System.out.println("createchart: inde="+independentVarLength);
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset[0], // data
            PlotOrientation.VERTICAL, legend, // include legend
            true, // tooltips
            false // urls
    );

    //printDataset(dataset, num_series);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot subplot1 = (XYPlot) chart.getPlot();
    subplot1.setBackgroundPaint(Color.lightGray);
    subplot1.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    subplot1.setDomainGridlinePaint(Color.white);
    subplot1.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) subplot1.getRenderer();

    renderer1.setBaseLinesVisible(false);
    renderer1.setBaseShapesVisible(true);
    renderer1.setBaseShapesFilled(true);

    int[] num_group = new int[num_series];
    Paint color_mainGroup = mEMexperiment[0].getColorOfMainGroup();

    // use same color   for all series if EM together    
    //  System.out.println("dataset0. seriescount="+dataset[0].getSeriesCount()+" itemcount="+dataset[0].getItemCount(0));
    if (num_series == 1)
        for (int s = 0; s < dataset[0].getSeriesCount(); s++) {
            renderer1.setSeriesLinesVisible(s, false);
            renderer1.setSeriesShapesVisible(s, true);
            renderer1.setSeriesShapesFilled(s, true);
            renderer1.setSeriesShape(s, series_shapes[0]); // for the shape of the dots
            renderer1.setSeriesPaint(s, color_mainGroup);
        }

    //  System.out.println("num_series="+num_series);
    //   System.out.println("num_group="+num_group);
    //  System.out.println("segment_flag="+segment_flag);

    if (legend) {
        LegendItemCollection legends_old = subplot1.getFixedLegendItems();
        LegendItemCollection legends_new = new LegendItemCollection();
        for (int s = 0; s < num_series; s++) {
            legends_new.add(legends_old.get(s));
        }
        subplot1.setFixedLegendItems(legends_new);

    }
    //segment

    for (int s = 0; s < num_series; s++) {
        num_group[s] = mEMexperiment[s].getNumOfGroup();
    }

    // System.out.println("num_group[0]="+num_group[0]);

    if (num_group[0] > 0 && segment_flag && (mixSelected == CG_MIX)) {
        Paint[] color_groups = mEMexperiment[0].getColorOfGroups();

        for (int i = 0; i < num_group[0] - 1; i++) {
            //System.out.println("color "+ i +"=" + color_groups[i].toString());
            renderer1.setSeriesPaint(i, color_groups[i]);
        }
        //System.out.println("color main ="+ color_mainGroup.toString());
        renderer1.setSeriesPaint(nkSelected, color_mainGroup);
    } else
        renderer1.setBasePaint(color_mainGroup);

    // renderer1.setShape(series_shapes[0]);   

    // subplot1.setDataset(0, dataset[0]);
    //System.out.println("setting renderer for " +0);
    //   subplot1.setRenderer(0, renderer1);
    // System.out.println("SOCR_EM creatChart: pt0="+dataset.getXValue(0, 0)+ ","+dataset.getYValue(0, 0));

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) subplot1.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    //   rangeAxis.setUpperMargin(0);
    //  rangeAxis.setLowerMargin(0);

    NumberAxis domainAxis = (NumberAxis) subplot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(true);
    //  domainAxis.setUpperMargin(0);
    //  domainAxis.setLowerMargin(0);

    XYLineAndShapeRenderer[] renderer1a = new XYLineAndShapeRenderer[num_series];
    if (num_series > 1) {
        for (int s = 0; s < num_series; s++) {
            //   System.out.println("adding pt for series:"+s +": seriesCount "+ dataset[s].getSeriesCount()+"itemcount="+dataset[s].getItemCount(0));
            renderer1a[s] = new XYLineAndShapeRenderer();
            if (num_group[0] > 0 && segment_flag && (mixSelected == CG_MIX)) {
                Paint[] color_groups = mEMexperiment[0].getColorOfGroups();

                for (int i = 0; i < num_group[0] - 1; i++) {
                    //System.out.println("color "+ i +"=" + color_groups[i].toString());
                    renderer1a[s].setSeriesPaint(i, color_groups[i]);
                }
                //System.out.println("color main ="+ color_mainGroup.toString());
                renderer1a[s].setSeriesPaint(nkSelected, color_mainGroup);
            } else
                renderer1a[s].setBasePaint(color_mainGroup);
            renderer1a[s].setBaseLinesVisible(false);
            renderer1a[s].setBaseShapesVisible(true);
            renderer1a[s].setBaseShapesFilled(true);
            renderer1a[s].setBaseShape(series_shapes[s]); // different shape of dots for each pair of input    
            subplot1.setDataset(s, dataset[s]);
            // System.out.println("setting renderer for " +s);
            subplot1.setRenderer(s, renderer1a[s]);
        }

    }

    if (kernels != null) {
        /*  System.out.println("draw kernels");
          System.out.println("num_series="+num_series);
          System.out.println("nkSelected="+nkSelected);*/
        XYLineAndShapeRenderer[][] renderer2 = new XYLineAndShapeRenderer[num_series][nkSelected];
        for (int s = 0; s < num_series; s++) {

            Paint[] color_kernels = mEMexperiment[s].getColorOfKernels();
            // System.out.println("SOCR_EM creatChart adding kernels:" +num_kernels+ "ws[0]="+ws[0]);
            for (int i = 0; i < nkSelected; i++) {
                // System.out.println("drawing kernel for series: "+s +" kernel:" +i);
                //  System.out.println("SOCR_EM creatChart: kernel "+i+" pt0="+kernels[i].getXValue(0, 0)+","+kernels[i].getYValue(0, 0));
                renderer2[s][i] = new XYLineAndShapeRenderer();
                renderer2[s][i].setBaseStroke(series_strokes[s]);
                renderer2[s][i].setBaseLinesVisible(true);
                renderer2[s][i].setBaseShapesVisible(false);
                //  renderer2[s][i].setShapesFilled(false);
                renderer2[s][i].setBasePaint(color_kernels[i]);
                subplot1.setDataset(num_series - 1 + s * num_series + i + 1, kernels[s][i]);
                // System.out.println("setting renderer for " +(num_series-1+s*num_series+i+1));
                subplot1.setRenderer(num_series - 1 + s * num_series + i + 1, renderer2[s][i]);
                //subplot1.setRangeAxis(i+1, rangeAxis);
            } //i
        } //s
    }

    segment_flag = false;
    return chart;

}

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private XYPlot getXYPlot(List<cfCHARTSERIESData> series, String xAxisTitle, String yAxisTitle,
        String labelFormat, boolean bShowMarkers, int markerSize, boolean bShow3D, String tipStyle,
        String drillDownUrl, int xOffset, int yOffset, int yAxisUnits, String seriesPlacement, int height,
        int gridLines) throws cfmRunTimeException {
    // Create an XY plot
    XYPlot plot = new XYPlot();
    ValueAxis domainAxis;/*  w ww.  j av  a 2s.  com*/

    if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_NUMERIC_SERIES) {
        if (bShow3D)
            domainAxis = new NumberAxis3D(xAxisTitle);
        else
            domainAxis = new NumberAxis(xAxisTitle);
    } else {
        domainAxis = new DateAxis(xAxisTitle);
    }
    plot.setDomainAxis(domainAxis);

    ValueAxis valueAxis;
    DateFormat dateFormat = null;
    NumberFormat numberFormat = null;
    if (labelFormat.equals("date")) {
        valueAxis = new DateAxis(yAxisTitle);
        dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        ((DateAxis) valueAxis).setDateFormatOverride(dateFormat);
    } else {
        if (bShow3D)
            valueAxis = new NumberAxis3D(yAxisTitle);
        else
            valueAxis = new NumberAxis(yAxisTitle);
        if (labelFormat.equals("currency")) {
            ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getCurrencyInstance());
            numberFormat = NumberFormat.getCurrencyInstance();
        } else if (labelFormat.equals("percent")) {
            numberFormat = NumberFormat.getPercentInstance();
            numberFormat.setMaximumFractionDigits(3); // without this change .11443
                                                      // would be displayed as 11%
                                                      // instead of 11.443%
            ((NumberAxis) valueAxis).setNumberFormatOverride(numberFormat);
        } else {
            numberFormat = NumberFormat.getInstance();
        }

        if (yAxisUnits != 0)
            ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits));
    }
    plot.setRangeAxis(valueAxis);

    // Add a dataset and renderer for each series
    int barChartDatasetIndex = -1;
    int hBarChartDatasetIndex = -1;
    int num = 0;
    MinMaxData minMax = new MinMaxData();
    for (int i = 0; i < series.size(); i++) {
        cfCHARTSERIESData seriesData = series.get(i);
        XYSeriesCollection dataset;
        if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) {
            dataset = (XYSeriesCollection) plot.getDataset(barChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex),
                    dataset.getSeriesCount() - 1, height);

            // Add the color list for this series to the custom color renderer
            CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(barChartDatasetIndex);
            cr.addColors(getColorList(seriesData));

            continue;
        } else if ((hBarChartDatasetIndex != -1) && (seriesData.getType().equals("horizontalbar"))) {
            dataset = (XYSeriesCollection) plot.getDataset(hBarChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex),
                    dataset.getSeriesCount() - 1, height);

            // Add the color list for this series to the custom color renderer
            CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(hBarChartDatasetIndex);
            cr.addColors(getColorList(seriesData));

            continue;
        } else {
            dataset = new XYSeriesCollection();

            addSeriesDataToDataset(seriesData, dataset, minMax);
        }

        plot.setDataset(num, dataset);

        XYItemRenderer renderer = null;
        if (seriesData.getType().equals("bar")) {
            plot.setOrientation(PlotOrientation.VERTICAL);
            renderer = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.TOP_CENTER);
            renderer.setNegativeItemLabelPosition(position2);
            ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each
                                                       // category

            barChartDatasetIndex = num;
        } else if (seriesData.getType().equals("horizontalbar")) {
            plot.setOrientation(PlotOrientation.HORIZONTAL);
            plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
            renderer = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
                    TextAnchor.CENTER_LEFT);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9,
                    TextAnchor.CENTER_RIGHT);
            renderer.setNegativeItemLabelPosition(position2);
            ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each
                                                       // category

            hBarChartDatasetIndex = num;
        } else if (seriesData.getType().equals("line")) {
            renderer = new XYLineAndShapeRenderer(true, false);

            // Enable/Disable displaying of markers
            ((XYLineAndShapeRenderer) renderer).setShapesVisible(bShowMarkers);

            // Set the shape of the markers based on the markerSize value
            ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        } else if (seriesData.getType().equals("area")) {
            renderer = new CustomXYAreaRenderer();
        } else if (seriesData.getType().equals("step")) {
            renderer = new CustomXYStepRenderer();
        } else if (seriesData.getType().equals("scatter")) {
            renderer = new XYLineAndShapeRenderer(false, true);

            // Set the shape of the markers based on the markerSize value
            ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        }

        if (!tipStyle.equals("none")) {
            if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) {
                renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: {1}",
                        DateFormat.getInstance(), DateFormat.getInstance()));
            } else {
                if (dateFormat != null)
                    renderer.setBaseToolTipGenerator(
                            new StandardXYToolTipGenerator("{0}: {2}", dateFormat, dateFormat));
                else
                    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
                            numberFormat, NumberFormat.getInstance()));
            }
        }

        if (drillDownUrl != null) {
            if (dateFormat != null)
                renderer.setURLGenerator(
                        new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, dateFormat));
            else
                renderer.setURLGenerator(
                        new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, numberFormat));
        }

        if (seriesData.getSeriesColor() != null)
            renderer.setSeriesPaint(0, convertStringToColor(seriesData.getSeriesColor()));

        String dataLabelStyle = seriesData.getDataLabelStyle();
        if (labelFormat.equals("date")) {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setXYItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value"))
                    renderer.setItemLabelGenerator(
                            new StandardXYItemLabelGenerator("{2}", dateFormat, dateFormat));
                else if (dataLabelStyle.equals("rowlabel"))
                    renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{0}",
                            NumberFormat.getInstance(), NumberFormat.getInstance()));
                else if (dataLabelStyle.equals("columnlabel"))
                    renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}",
                            NumberFormat.getInstance(), NumberFormat.getInstance()));
                else if (dataLabelStyle.equals("pattern"))
                    renderer.setItemLabelGenerator(new XYItemLabelGenerator("{2}", dateFormat, dateFormat));
                else
                    renderer.setItemLabelGenerator(
                            new XYItemLabelGenerator(dataLabelStyle, dateFormat, dateFormat));
            }
        } else {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setXYItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value")) {

                    renderer.setItemLabelGenerator(
                            new StandardXYItemLabelGenerator("{2}", numberFormat, numberFormat));

                } else if (dataLabelStyle.equals("rowlabel")) {

                    renderer.setItemLabelGenerator(
                            new StandardXYItemLabelGenerator("{0}", numberFormat, numberFormat));

                } else if (dataLabelStyle.equals("columnlabel")) {

                    if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) {
                        renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}",
                                SimpleDateFormat.getInstance(), NumberFormat.getInstance()));
                    } else {
                        renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}",
                                NumberFormat.getInstance(), NumberFormat.getInstance()));
                    }

                } else if (dataLabelStyle.equals("pattern")) {

                    if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) {
                        renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})",
                                SimpleDateFormat.getInstance(), numberFormat));
                    } else {
                        renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})",
                                NumberFormat.getInstance(), numberFormat));
                    }

                } else {
                    renderer.setItemLabelGenerator(
                            new XYItemLabelGenerator(dataLabelStyle, NumberFormat.getInstance(), numberFormat));
                }
            }
        }

        // Add the renderer to the plot.
        // NOTE: this must be done before the setPaintStyle() call so the
        // DrawingSupplier object
        // will be set up properly for the generation of default colors.
        plot.setRenderer(num, renderer);

        // Set the paint style for this series (series 0)
        if (seriesData.getType().equals("bar") || seriesData.getType().equals("horizontalbar")
                || seriesData.getType().equals("area"))
            setPaintStyle(seriesData.getPaintStyle(), renderer, 0, height);

        num++;
    }

    // If gridLines was specified then we need to calculate the yAxisUnits
    if ((gridLines != -1) && (valueAxis instanceof NumberAxis)) {
        // Calculate the yAxisUnits we need to use to create the number of
        // gridLines
        yAxisUnits = calculateYAxisUnits(gridLines, minMax);

        // Set the yAxisUnits
        ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits));
    }

    return plot;
}

From source file:msi.gama.outputs.layers.ChartLayerStatement.java

void createSeries(final IScope scope, final boolean isTimeSeries) throws GamaRuntimeException {
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setTickLabelFont(getTickFont());
    domainAxis.setLabelFont(getLabelFont());
    if (isTimeSeries) {
        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        if (timeSeriesXData == null) {
            timeSeriesXData = (ChartDataStatement) DescriptionFactory.create(IKeyword.DATA, description,
                    IKeyword.LEGEND, xAxisName, IKeyword.VALUE, SimulationAgent.CYCLE).compile();
            if (getFacet(IKeyword.TIMEXSERIES) != null) {
                timeSeriesXData.getDescription().getFacets().get(IKeyword.VALUE)
                        .setExpression(getFacet(IKeyword.TIMEXSERIES));
            }/*from   w  w  w . j ava 2  s .com*/
        }

        // FIXME: datas can NOT contain timeSeriesXData (a ChartDataStatement and not a ChartData)
        if (!datas.contains(timeSeriesXData)) {
            datas.add(0, timeSeriesXData.createData(scope));
        }
    }
    IExpression expr = getFacet(XRANGE);
    IExpression expr2 = getFacet(XTICKUNIT);
    if (expr != null) {
        Object range = expr.value(scope);
        // Double range = Cast.asFloat(scope, expr.value(scope));

        if (range instanceof Number) {
            double r = ((Number) range).doubleValue();
            if (r > 0) {
                domainAxis.setFixedAutoRange(r);
                domainAxis.setAutoRangeMinimumSize(r);
            }
            domainAxis.setAutoRangeIncludesZero(false);
        } else if (range instanceof GamaPoint) {
            domainAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY());
        }
    }
    if (expr2 != null) {
        Object range = expr2.value(scope);
        // Double range = Cast.asFloat(scope, expr.value(scope));

        if (range instanceof Number) {
            double r = ((Number) range).doubleValue();
            if (r > 0) {
                domainAxis.setTickUnit(new NumberTickUnit(r));
            }
        }
    }
    if (datas.size() > 0) {
        domainAxis.setLabel(datas.get(0).getName());
    }
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setTickLabelFont(getTickFont());
    yAxis.setLabelFont(getLabelFont());
    expr = getFacet(YRANGE);
    expr2 = getFacet(YTICKUNIT);
    if (expr != null) {
        Object range = expr.value(scope);
        // Double range = Cast.asFloat(scope, expr.value(scope));

        if (range instanceof Number) {
            double r = ((Number) range).doubleValue();
            if (r > 0) {
                yAxis.setFixedAutoRange(r);
                yAxis.setAutoRangeMinimumSize(r);
            }
            yAxis.setAutoRangeIncludesZero(false);
        } else if (range instanceof GamaPoint) {
            yAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY());
        }
    }
    if (expr2 != null) {
        Object range = expr2.value(scope);
        // Double range = Cast.asFloat(scope, expr.value(scope));

        if (range instanceof Number) {
            double r = ((Number) range).doubleValue();
            if (r > 0) {
                yAxis.setTickUnit(new NumberTickUnit(r));
            }
        }
    }
    if (datas.size() == 2) {
        yAxis.setLabel(datas.get(1).getName());
        chart.removeLegend();
    }
    final LegendTitle ll = chart.getLegend();
    if (ll != null) {
        ll.setItemFont(getLegendFont());
    }

    for (int i = 0; i < datas.size(); i++) {
        ChartData e = datas.get(i);

        final String legend = e.getName();
        if (i != 0 | !isTimeSeries) { // the first data is the domain

            XYDataset data = plot.getDataset(i);
            XYSeries serie = new XYSeries(0, false, false);
            if (type == SERIES_CHART || type == XY_CHART) {
                dataset = new DefaultTableXYDataset();
                // final XYSeries nserie = new XYSeries(serie.getKey(), false, false);
                final XYSeries nserie = new XYSeries(e.getName(), false, false);
                ((DefaultTableXYDataset) dataset).addSeries(nserie);
            }
            if (type == SCATTER_CHART) {
                dataset = new XYSeriesCollection();
                final XYSeries nserie = new XYSeries(e.getName(), false, true);
                // final XYSeries nserie = new XYSeries(serie.getKey(), false, true);
                ((XYSeriesCollection) dataset).addSeries(nserie);
            }

            // dataset = new DefaultTableXYDataset();

            // final XYSeries serie = new XYSeries(legend, false, false);
            // final XYSeries serie = new XYSeries(legend, false, true);
            // ((DefaultTableXYDataset) dataset).addSeries(serie);
            expressions_index.put(legend, i);
            plot.setRenderer(i, (XYItemRenderer) e.getRenderer(), false);
            // final Color c = e.getColor();
            // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesPaint(0, c);
            // TODO Control this with a facet
            // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setBaseShapesFilled(false);
            // TODO Control this with a facet
            // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesShapesVisible(0, false);
            // if (type==SERIES_CHART)
            // plot.setDataset(i-1, (DefaultTableXYDataset) dataset);
            // else
            plot.setDataset(i, (XYDataset) dataset);
        }
        history.append(legend);
        history.append(',');

    }
    if (history.length() > 0) {
        history.deleteCharAt(history.length() - 1);
    }
    history.append(Strings.LN);

}

From source file:v800_trainer.XYGraphik.java

public JPanel StartGraphik(JCicloTronic JTronicHandle) {

    int num = 0;/*from w ww.j  a v a2  s .  c o m*/
    int num2 = 0, num0, num02; //fr Streckendifferenz
    int selected;
    int single;
    int i;
    int j;
    int Stunden;
    int Minuten;
    int Sekunden;
    int Tagadder = 0;
    int Linecount = 0;
    Second xTime[];
    double xWerte[];
    double xWerte2[];//fr Streckendifferenz
    double y1Werte[];
    double y2Werte[];
    double y3Werte[];
    double y4Werte[];
    double y5Werte[];
    double y6Werte[];
    double y7Werte[];
    double y8Werte[];
    double y8bWerte[];
    double y9Werte[];
    double y10Werte[];

    JFreeChart chart;

    Rectangle2D.Double Legendenpunkt = new Rectangle2D.Double();

    selected = JTronicHandle.Auswahl_Graphik.getSelectedIndex();

    if (selected == 0) {
        single = 1;
    } else {
        single = 0;
    }

    //Defaultchart erstellen
    if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) {

        XYSeries dataset = new XYSeries("");

        dataset.add(1, 1);
        XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

        chart = ChartFactory.createXYLineChart("Multiple Axis Demo 1", "Strecke", "", dataset1,
                PlotOrientation.HORIZONTAL, true, true, false);

    } else {
        TimeSeries dataset = new TimeSeries("");

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

        TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

        chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Zeit", "", dataset1, true, true,
                false);
    }
    ;
    //Tooltips fr Zeitachse einstellen
    //    XYToolTipGenerator ToolTip = new StandardXYToolTipGenerator("{0}: ({1}, {2})",
    //            (DateFormat) new SimpleDateFormat("kk:mm.ss"),
    //            NumberFormat.getInstance());

    //  chart.setAntiAlias(true);
    chart.setNotify(false);

    if (single == 0) {
        chart.setTitle(JTronicHandle.Statistikhandle.TourData[JTronicHandle.Auswahl_Graphik
                .getSelectedIndex()].DataProperty.getProperty("Titel", ""));
        chart.addSubtitle(new TextTitle(JTronicHandle.Auswahl_Graphik.getItemAt(selected).toString()));
    } else {
        chart.setTitle("Mehrfache Daten");
    }

    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.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(false);
    plot.setDomainCrosshairLockedOnData(false);

    int Anzahl_Kurven = Integer.parseInt(JTronicHandle.Properties.getProperty("AnzahlKurven", "5")) + 1;

    if (Anzahl_Kurven > JTronicHandle.Auswahl_Graphik.getItemCount()) {
        Anzahl_Kurven = JTronicHandle.Auswahl_Graphik.getItemCount();
    }

    try {

        for (j = 0; j < (Anzahl_Kurven - 2) * single + 1; j++) {
            if (single == 1) {
                selected = j + 1;
            }
            num = JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
            num2 = JTronicHandle.Statistikhandle.TourData[selected].ZahlStreckenPunkte;
            num0 = JTronicHandle.Statistikhandle.TourData[1].ZahlStreckenPunkte;
            num02 = JTronicHandle.Statistikhandle.TourData[1].Datenpunkte;
            xTime = new Second[num];
            xWerte = new double[num];
            y1Werte = new double[num];
            y2Werte = new double[num];
            y3Werte = new double[num];
            y4Werte = new double[num];
            y5Werte = new double[num];
            y6Werte = new double[num];
            y7Werte = new double[num];
            y8Werte = new double[num];
            y8bWerte = new double[num];
            xWerte2 = new double[num2];
            y9Werte = new double[num2];
            y10Werte = new double[num];

            for (i = 0; i < num; i++) {
                xWerte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Strecke_gesZeit[i];
                y1Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Geschw_gesZeit[i];
                y2Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Hoehe_gesZeit[i];
                y3Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Hf_gesZeit[i];
                y4Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Temperatur_gesZeit[i];
                y5Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Steigp_gesZeit[i];
                y6Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Steigm_gesZeit[i];
                y7Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].av_Geschw_gesZeit[i];
                y8Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Cadence_gesZeit[i];
                y8bWerte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Schritt_lnge[i];
            }

            if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) {
                int p = 0;
                if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) {
                    for (i = 0; i < num2; i++) {
                        xWerte2[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Streckenskala[i];
                        if (i < num0) {
                            y9Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].ZeitberStrecke[i]
                                    - JTronicHandle.Statistikhandle.TourData[1].ZeitberStrecke[i];
                        } else {
                            y9Werte[i] = y9Werte[i - 1];
                        }
                    }
                } else {
                    for (i = 0; i < num; i++) {
                        p = 0;
                        while (p < num02 - 1
                                && (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] >= JTronicHandle.Statistikhandle.TourData[1].gesZeit[p])) {
                            p++;
                        }
                        ;
                        if (i < num02) {
                            y10Werte[i] = (double) (JTronicHandle.Statistikhandle.TourData[selected].Strecke_gesZeit[i]
                                    - JTronicHandle.Statistikhandle.TourData[1].Strecke_gesZeit[p]) * 100.0;
                        } else {
                            y10Werte[i] = y10Werte[i - 1];
                        }
                    }
                }
            }

            //Zeitbasis laden
            for (i = 0; i < num; i++) {
                Tagadder = 0;
                Stunden = (int) (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] / 3600);
                Minuten = (int) ((JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] - Stunden * 3600)
                        / 60);
                Sekunden = (int) (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] - Stunden * 3600
                        - Minuten * 60);
                if (single == 0) {
                    Minuten = Minuten + JTronicHandle.Statistikhandle.TourData[selected].StartMinuten;
                    if (Minuten >= 60) {
                        Minuten -= 60;
                        Stunden++;
                    }
                    ;
                    Stunden = Stunden + JTronicHandle.Statistikhandle.TourData[selected].StartStunden;
                }
                ;
                while (Stunden >= 24) {
                    Stunden -= 24;
                    Tagadder += 1;
                }
                ;

                try {
                    if (single == 0) {
                        xTime[i] = new Second(Sekunden, Minuten, Stunden,
                                JTronicHandle.Statistikhandle.TourData[selected].Tag + Tagadder,
                                JTronicHandle.Statistikhandle.TourData[selected].Monat,
                                JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    } else {
                        xTime[i] = new Second(Sekunden, Minuten, Stunden, 1 + Tagadder, 1, 1900);
                    }

                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "StartGraphik\n" + e + "Zeile " + i + " Zeitfehler "
                            + Stunden + " " + Minuten + " " + Sekunden, "Achtung!", JOptionPane.ERROR_MESSAGE);
                }
            }

            if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { //Streckenachse

                if (JTronicHandle.Graphik_check_Geschwindigkeit.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Geschwindigkeit [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag
                                    + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y1Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //          renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Hhe.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Hhe [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);

                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y2Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);
                    NumberAxis axis2 = new NumberAxis("Hhe [m]");
                    axis2.setLabelFont(plot.getRangeAxis().getLabelFont());
                    axis2.setTickLabelFont(plot.getRangeAxis().getTickLabelFont());
                    axis2.setAutoRangeIncludesZero(true);
                    axis2.setLabelPaint(Color.BLACK);
                    axis2.setTickLabelPaint(Color.BLACK);
                    axis2.setAxisLinePaint(Color.BLACK);
                    plot.setRangeAxis(1, axis2);
                    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 1);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //               renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }
                ;

                if (JTronicHandle.Graphik_check_HF.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Herzfrequenz [b/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y3Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Temp.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Temperatur [C] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y4Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Steigung_p.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Steigung [%] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y5Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //          renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Steigung_m.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Steigung [m/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y6Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //              renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_av_Geschw.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "av Geschw. [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y7Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //              renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Cadence.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Cadence [n/min]  " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y8Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //               renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Schrittlnge.isSelected()) {

                    XYSeries dataset = new XYSeries(
                            "Schrittlnge [cm]  " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xWerte[i], y8bWerte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //                  renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) {

                    XYSeries dataset = new XYSeries(
                            "Zeitabstand [s] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr + " - "
                                    + JTronicHandle.Statistikhandle.TourData[1].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[1].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[1].Jahr);
                    for (i = 0; i < num2; i++) {
                        dataset.add(xWerte2[i], y9Werte[i]);
                    }

                    XYSeriesCollection dataset1 = new XYSeriesCollection(dataset);

                    NumberAxis axis3 = new NumberAxis("Abstand");
                    axis3.setLabelFont(plot.getRangeAxis().getLabelFont());
                    axis3.setTickLabelFont(plot.getRangeAxis().getTickLabelFont());

                    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, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 2);
                    XYItemRenderer renderer = new StandardXYItemRenderer();
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //             renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

            } else { //Zeitachse

                if (JTronicHandle.Graphik_check_Geschwindigkeit.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Geschwindigkeit [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag
                                    + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y1Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    ValueAxis axis = plot.getRangeAxis();

                    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);

                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));

                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Hhe.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Hoehe [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y2Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);
                    NumberAxis axis2 = (NumberAxis) plot.getRangeAxis().clone();
                    axis2.setLabel("Hhe [m]");

                    axis2.setAutoRangeIncludesZero(true);

                    axis2.setLabelPaint(Color.BLACK);
                    axis2.setTickLabelPaint(Color.BLACK);
                    axis2.setAxisLinePaint(Color.BLACK);
                    plot.setRangeAxis(1, axis2);
                    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 1);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_HF.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Herzfrequenz [b/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y3Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Temp.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Temperatur [C] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y4Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //          renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Steigung_p.isSelected()) {

                    TimeSeries dataset = new TimeSeries("Steigung [%] ");
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y5Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //           renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Steigung_m.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Steigung [m/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y6Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //           renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_av_Geschw.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "av Geschw. [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y7Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //              renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Cadence.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Cadence [n/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y8Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //          renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Schrittlnge.isSelected()) {

                    TimeSeries dataset = new TimeSeries(
                            "Schrittlnge [cm] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y8bWerte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 0);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //                renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

                if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) {

                    TimeSeries dataset = new TimeSeries(
                            "Streckenabstand [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[selected].Jahr + " - "
                                    + JTronicHandle.Statistikhandle.TourData[1].Tag + "."
                                    + JTronicHandle.Statistikhandle.TourData[1].Monat + "."
                                    + JTronicHandle.Statistikhandle.TourData[1].Jahr);
                    for (i = 0; i < num; i++) {
                        dataset.add(xTime[i], y10Werte[i]);
                    }

                    TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset);

                    ValueAxis axis3 = (ValueAxis) plot.getRangeAxis().clone();

                    axis3.setLabel("Abstand");
                    axis3.setLabelPaint(Color.BLACK);
                    axis3.setTickLabelPaint(Color.BLACK);
                    plot.setRangeAxis(2, axis3);
                    plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT);

                    plot.setDataset(Linecount, dataset1);
                    plot.mapDatasetToRangeAxis(Linecount, 2);
                    XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip);
                    renderer.setSeriesPaint(0, getColour(Linecount));
                    //            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                    plot.setRenderer(Linecount, renderer);

                    Linecount++;
                }

            }

        }
        chart.setNotify(true);
        ChartPanel Panel = new ChartPanel(chart);

        return Panel;

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "StartGraphik\nSchluss_Fehler: " + e, "Achtung!",
                JOptionPane.ERROR_MESSAGE);
    }

    return new ChartPanel(chart);
}