Example usage for org.jfree.chart.axis LogarithmicAxis setAllowNegativesFlag

List of usage examples for org.jfree.chart.axis LogarithmicAxis setAllowNegativesFlag

Introduction

In this page you can find the example usage for org.jfree.chart.axis LogarithmicAxis setAllowNegativesFlag.

Prototype

public void setAllowNegativesFlag(boolean flgVal) 

Source Link

Document

Sets the 'allowNegativesFlag' flag; true to allow negative values in data, false to be able to plot positive values arbitrarily close to zero.

Usage

From source file:org.matsim.counts.algorithms.graphs.CountsSimReal24Graph.java

@Override
public JFreeChart createChart(final int nbr) {

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series = new XYSeries("MATSim volumes");
    // easier to use another dataset
    XYSeriesCollection dataset_outliers = new XYSeriesCollection();
    XYSeries series_outliers = new XYSeries("MATSim outliers");

    CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
    CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();

    final ArrayList<String> urls = new ArrayList<>();
    final ArrayList<String> tooltips = new ArrayList<>();
    List<Comp> comps = new Vector<>();

    //--------------------
    CountSimComparisonLinkFilter linkFilter = new CountSimComparisonLinkFilter(this.ccl_);

    final Vector<Id<Link>> linkIds = new CountSimComparisonLinkFilter(this.ccl_).getLinkIds();
    Iterator<Id<Link>> id_it = linkIds.iterator();

    double maxCountValue = 0.1;
    double maxSimValue = 0.1;
    // yyyy PtCountsKMLWriterTest.testPtAlightKMLCreation never touches these and then leads to an exception later
    // when they are zero.  Don't know why. kai, sep'16

    while (id_it.hasNext()) {
        Id<Link> id = id_it.next();

        double countVal = linkFilter.getAggregatedCountValue(id);
        double simVal = linkFilter.getAggregatedSimValue(id);

        if (countVal > 100.0 && simVal > 100.0) {

            if (countVal > maxCountValue)
                maxCountValue = countVal;
            if (simVal > maxSimValue)
                maxSimValue = simVal;/*w  w  w.  ja  va  2s .co m*/

            series.add(countVal, simVal);
            comps.add(new Comp(countVal, "link" + id + ".html",
                    "Link " + id + "; " + "Count: " + countVal + ", Sim: " + simVal));
        } else {
            /* values with simVal<100.0 or countVal<100.0 are drawn on the x==100 or/and y==100-line
             */
            countVal = Math.max(100.0, countVal);
            simVal = Math.max(100.0, simVal);
            series_outliers.add(countVal, simVal);

            if (countVal > maxCountValue)
                maxCountValue = countVal;
            if (simVal > maxSimValue)
                maxSimValue = simVal;
        }
    } //while
    dataset0.addSeries(series);
    dataset_outliers.addSeries(series_outliers);

    Collections.sort(comps, new MyComparator());

    for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
        Comp cp = iter.next();
        urls.add(cp.getURL());
        tooltips.add(cp.getTooltip());
    }

    url_gen.addURLSeries(urls);
    tt_gen.addToolTipSeries(tooltips);

    String title = "Avg. Weekday Traffic Volumes, Iteration: " + this.iteration_;
    this.setChartTitle(title);
    this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes", // x axis label
            "Sim Volumes", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            true // urls
    );
    XYPlot plot = this.chart_.getXYPlot();
    final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/24h]");
    final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/24h]");
    axis_x.setAllowNegativesFlag(false);
    axis_y.setAllowNegativesFlag(false);

    //regular values
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setURLGenerator(url_gen);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesToolTipGenerator(0, tt_gen);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    //outliers
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setLinesVisible(false);
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    // error band
    DefaultXYDataset dataset1 = new DefaultXYDataset();
    Gbl.assertIf(maxCountValue > 0.);
    dataset1.addSeries("f1x", new double[][] { { 100.0, maxCountValue }, { 100.0, maxCountValue } });
    dataset1.addSeries("f2x", new double[][] { { 100.0, maxCountValue }, { 200.0, 2 * maxCountValue } });
    dataset1.addSeries("f05x", new double[][] { { 200.0, maxCountValue }, { 100.0, 0.5 * maxCountValue } });

    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
    renderer3.setShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.blue);
    renderer3.setSeriesPaint(1, Color.blue);
    renderer3.setSeriesPaint(2, Color.blue);
    renderer3.setBaseSeriesVisibleInLegend(false);
    renderer3.setSeriesItemLabelsVisible(0, true);
    renderer3.setSeriesItemLabelsVisible(1, false);
    renderer3.setSeriesItemLabelsVisible(2, false);

    XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", maxCountValue, 2 * maxCountValue);
    annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation0);
    XYTextAnnotation annotation1 = new XYTextAnnotation("count", maxCountValue, maxCountValue);
    annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation1);
    XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", maxCountValue, 0.5 * maxCountValue);
    annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation2);

    plot.setDomainAxis(axis_x);
    plot.setRangeAxis(axis_y);
    plot.setRenderer(0, renderer);

    plot.setRenderer(1, renderer2);
    plot.setDataset(1, dataset_outliers);

    plot.setRenderer(2, renderer3);
    plot.setDataset(2, dataset1);

    //plot.getRangeAxis().setRange(1.0, 19000.0);
    //plot.getDomainAxis().setRange(1.0, 19000.0);

    return this.chart_;
}

From source file:org.matsim.pt.counts.PtCountsSimRealPerHourGraph.java

/**
 * @param hour//from w  w  w. j a  v  a 2s.  c  o m
 *            A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2
 *            a.m. ...
 */
@Override
public JFreeChart createChart(final int hour) {
    this.hour = hour;

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series = new XYSeries("MATSim volumes");
    // easier to use another dataset
    XYSeriesCollection dataset_outliers = new XYSeriesCollection();
    XYSeries series_outliers = new XYSeries("MATSim outliers");

    CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
    CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();

    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<String> tooltips = new ArrayList<String>();
    List<Comp> comps = new Vector<Comp>();

    Iterator<CountSimComparison> l_it = this.ccl_.iterator();
    // int elementCounter=0;
    while (l_it.hasNext()) {
        CountSimComparison cc = l_it.next();

        /*
         * values with simVal==0.0 or countVal==0.0 are drawn on the x==1
         * or/and y==1-line Such values are the result of a poor simulation
         * run, but they can also represent a valid result (closing summer
         * road during winter time)
         */
        if (cc.getHour() == hour) {
            // elementCounter++;
            double realVal = 1.0;
            double simVal = 1.0;
            if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) {
                realVal = cc.getCountValue();
                simVal = cc.getSimulationValue();
                series.add(realVal, simVal);
                comps.add(new Comp(realVal, "link" + cc.getId() + ".html",
                        "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal));
            } else {
                realVal = Math.max(1.0, cc.getCountValue());
                simVal = Math.max(1.0, cc.getSimulationValue());
                series_outliers.add(realVal, simVal);
            }

        } // if
    } // while
    dataset0.addSeries(series);
    dataset_outliers.addSeries(series_outliers);

    /*
     * first we have to sort the vector according to the rendering ordering
     * (which is the x value). REALLY??? After hours of searching no better
     * solution found! please help!
     */

    Collections.sort(comps, new MyComparator());

    for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
        Comp cp = iter.next();
        urls.add(cp.getURL());
        tooltips.add(cp.getTooltip());
    }

    url_gen.addURLSeries(urls);
    tt_gen.addToolTipSeries(tooltips);

    String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: "
            + this.iteration_;
    this.setChartTitle(title);
    this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label
            "Sim Volumes [veh/h]", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            true // urls
    );
    XYPlot plot = this.chart_.getXYPlot();
    final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]");
    final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]");
    axis_x.setAllowNegativesFlag(false);
    axis_y.setAllowNegativesFlag(false);

    // regular values
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setURLGenerator(url_gen);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesToolTipGenerator(0, tt_gen);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    // outliers
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setLinesVisible(false);
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    // error band
    DefaultXYDataset dataset1 = new DefaultXYDataset();
    dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } });
    dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } });
    dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } });

    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
    renderer3.setShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.blue);
    renderer3.setSeriesPaint(1, Color.blue);
    renderer3.setSeriesPaint(2, Color.blue);
    renderer3.setBaseSeriesVisibleInLegend(false);
    renderer3.setSeriesItemLabelsVisible(0, true);
    renderer3.setSeriesItemLabelsVisible(1, false);
    renderer3.setSeriesItemLabelsVisible(2, false);

    XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0);
    annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation0);
    XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0);
    annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation1);
    XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0);
    annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation2);

    plot.setDomainAxis(axis_x);
    plot.setRangeAxis(axis_y);
    plot.setRenderer(0, renderer);

    plot.setRenderer(1, renderer2);
    plot.setDataset(1, dataset_outliers);

    plot.setRenderer(2, renderer3);
    plot.setDataset(2, dataset1);

    plot.getRangeAxis().setRange(1.0, 19000.0);
    plot.getDomainAxis().setRange(1.0, 19000.0);

    return this.chart_;
}

From source file:org.matsim.pt.counts.obsolete.PtCountsSimRealPerHourGraph.java

/**
 * @param hour/* ww w.ja va 2  s .c om*/
 *            A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2
 *            a.m. ...
 */
@Override
@Deprecated // use standard counts package
public JFreeChart createChart(final int hour) {
    this.hour = hour;

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series = new XYSeries("MATSim volumes");
    // easier to use another dataset
    XYSeriesCollection dataset_outliers = new XYSeriesCollection();
    XYSeries series_outliers = new XYSeries("MATSim outliers");

    CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
    CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();

    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<String> tooltips = new ArrayList<String>();
    List<Comp> comps = new Vector<Comp>();

    Iterator<CountSimComparison> l_it = this.ccl_.iterator();
    // int elementCounter=0;
    while (l_it.hasNext()) {
        CountSimComparison cc = l_it.next();

        /*
         * values with simVal==0.0 or countVal==0.0 are drawn on the x==1
         * or/and y==1-line Such values are the result of a poor simulation
         * run, but they can also represent a valid result (closing summer
         * road during winter time)
         */
        if (cc.getHour() == hour) {
            // elementCounter++;
            double realVal = 1.0;
            double simVal = 1.0;
            if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) {
                realVal = cc.getCountValue();
                simVal = cc.getSimulationValue();
                series.add(realVal, simVal);
                comps.add(new Comp(realVal, "link" + cc.getId() + ".html",
                        "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal));
            } else {
                realVal = Math.max(1.0, cc.getCountValue());
                simVal = Math.max(1.0, cc.getSimulationValue());
                series_outliers.add(realVal, simVal);
            }

        } // if
    } // while
    dataset0.addSeries(series);
    dataset_outliers.addSeries(series_outliers);

    /*
     * first we have to sort the vector according to the rendering ordering
     * (which is the x value). REALLY??? After hours of searching no better
     * solution found! please help!
     */

    Collections.sort(comps, new MyComparator());

    for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
        Comp cp = iter.next();
        urls.add(cp.getURL());
        tooltips.add(cp.getTooltip());
    }

    url_gen.addURLSeries(urls);
    tt_gen.addToolTipSeries(tooltips);

    String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: "
            + this.iteration_;
    this.setChartTitle(title);
    this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label
            "Sim Volumes [veh/h]", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            true // urls
    );
    XYPlot plot = this.chart_.getXYPlot();
    final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]");
    final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]");
    axis_x.setAllowNegativesFlag(false);
    axis_y.setAllowNegativesFlag(false);

    // regular values
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setURLGenerator(url_gen);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesToolTipGenerator(0, tt_gen);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    // outliers
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setLinesVisible(false);
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    // error band
    DefaultXYDataset dataset1 = new DefaultXYDataset();
    dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } });
    dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } });
    dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } });

    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
    renderer3.setShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.blue);
    renderer3.setSeriesPaint(1, Color.blue);
    renderer3.setSeriesPaint(2, Color.blue);
    renderer3.setBaseSeriesVisibleInLegend(false);
    renderer3.setSeriesItemLabelsVisible(0, true);
    renderer3.setSeriesItemLabelsVisible(1, false);
    renderer3.setSeriesItemLabelsVisible(2, false);

    XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0);
    annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation0);
    XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0);
    annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation1);
    XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0);
    annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation2);

    plot.setDomainAxis(axis_x);
    plot.setRangeAxis(axis_y);
    plot.setRenderer(0, renderer);

    plot.setRenderer(1, renderer2);
    plot.setDataset(1, dataset_outliers);

    plot.setRenderer(2, renderer3);
    plot.setDataset(2, dataset1);

    plot.getRangeAxis().setRange(1.0, 19000.0);
    plot.getDomainAxis().setRange(1.0, 19000.0);

    return this.chart_;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

@Override
public void resetAxes(final IScope scope) {
    NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis();

    if (getX_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(domainAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((XYPlot) this.chart.getPlot()).setDomainAxis(logAxis);
        domainAxis = logAxis;//from   w  w w. j a  v  a  2 s. c om
    }
    if (getY_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((XYPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;
    }
    if (!usexrangeinterval && !usexrangeminmax) {
        //         domainAxis.setAutoRangeMinimumSize(0.5);
        //         domainAxis.setAutoRange(true);
    }

    if (this.usexrangeinterval) {
        domainAxis.setFixedAutoRange(xrangeinterval);
        domainAxis.setAutoRangeMinimumSize(xrangeinterval);
        domainAxis.setAutoRange(true);
    }
    if (this.usexrangeminmax) {
        domainAxis.setRange(xrangemin, xrangemax);
    }

    if (!useyrangeinterval && !useyrangeminmax) {
        //      rangeAxis.setAutoRangeMinimumSize(0.5);
        //      rangeAxis.setAutoRange(true);
    }

    if (this.useyrangeinterval) {
        rangeAxis.setFixedAutoRange(yrangeinterval);
        rangeAxis.setAutoRangeMinimumSize(yrangeinterval);
        rangeAxis.setAutoRange(true);
    }
    if (this.useyrangeminmax) {
        rangeAxis.setRange(yrangemin, yrangemax);
    }
    if (this.series_label_position.equals("none")) {
        if ((this.chart).getLegend() != null)
            (this.chart).getLegend().setVisible(false);
    }
    if (!this.getXTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(false);

    }
    if (!this.getYTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false);

    }

}

From source file:com.sun.japex.ChartGenerator.java

private JFreeChart generateDriverScatterChart() {
    try {/* ww w.  j av  a  2s. c om*/
        DefaultTableXYDataset xyDataset = new DefaultTableXYDataset();

        // Generate charts
        for (DriverImpl di : _testSuite.getDriverInfoList()) {
            if (!di.hasParam(Constants.RESULT_ARIT_MEAN_X)) {
                System.out.println("Error: Driver '" + di.getName() + "' does not define"
                        + " any values for the X axis needed to generate a scatter chart");
                System.exit(1);
            }

            XYSeries xySeries = new XYSeries(di.getName(), true, false);
            xySeries.add(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X),
                    di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN));
            xySeries.add(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X),
                    di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN));
            xySeries.add(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X),
                    di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN));
            xyDataset.addSeries(xySeries);
        }

        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        JFreeChart chart = ChartFactory.createScatterPlot("Result Summary", resultUnitX, resultUnit, xyDataset,
                PlotOrientation.VERTICAL, true, true, false);

        // Set log scale depending on japex.resultAxis[_X]
        XYPlot plot = chart.getXYPlot();
        if (_testSuite.getParam(Constants.RESULT_AXIS_X).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxisX = new LogarithmicAxis(resultUnitX);
            logAxisX.setAllowNegativesFlag(true);
            plot.setDomainAxis(logAxisX);
        }
        if (_testSuite.getParam(Constants.RESULT_AXIS).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxis = new LogarithmicAxis(resultUnit);
            logAxis.setAllowNegativesFlag(true);
            plot.setRangeAxis(logAxis);
        }

        return chart;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.sun.japex.ChartGenerator.java

private int generateTestCaseScatterCharts(String baseName, String extension) {
    int nOfFiles = 0;
    List<DriverImpl> driverInfoList = _testSuite.getDriverInfoList();

    try {//from   www  .  j av a  2  s .c  o m
        // Get number of tests from first driver
        final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size();

        DefaultTableXYDataset xyDataset = new DefaultTableXYDataset();

        // Generate charts
        for (DriverImpl di : driverInfoList) {
            XYSeries xySeries = new XYSeries(di.getName(), true, false);
            for (int j = 0; j < nOfTests; j++) {
                TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(j);
                try {
                    xySeries.add(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X),
                            tc.getDoubleParamNoNaN(Constants.RESULT_VALUE));
                } catch (SeriesException e) {
                    // Ignore duplicate x-valued points
                }

            }
            xyDataset.addSeries(xySeries);
        }

        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        JFreeChart chart = ChartFactory.createScatterPlot("Results Per Test", resultUnitX, resultUnit,
                xyDataset, PlotOrientation.VERTICAL, true, true, false);

        // Set log scale depending on japex.resultAxis[_X]
        XYPlot plot = chart.getXYPlot();
        if (_testSuite.getParam(Constants.RESULT_AXIS_X).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxisX = new LogarithmicAxis(resultUnitX);
            logAxisX.setAllowNegativesFlag(true);
            plot.setDomainAxis(logAxisX);
        }
        if (_testSuite.getParam(Constants.RESULT_AXIS).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxis = new LogarithmicAxis(resultUnit);
            logAxis.setAllowNegativesFlag(true);
            plot.setRangeAxis(logAxis);
        }

        chart.setAntiAlias(true);
        ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension), chart,
                _chartWidth, _chartHeight);
        nOfFiles++;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return nOfFiles;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHistogram.java

@Override
public void resetAxes(final IScope scope) {
    final CategoryPlot pp = (CategoryPlot) this.chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) ((CategoryPlot) this.chart.getPlot()).getRangeAxis();
    if (getY_LogScale(scope)) {
        final LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((CategoryPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;//from w ww  .j a  v a 2 s . c  om
    }

    if (!useyrangeinterval && !useyrangeminmax) {
        rangeAxis.setAutoRange(true);
    }

    if (this.useyrangeinterval) {
        rangeAxis.setFixedAutoRange(yrangeinterval);
        rangeAxis.setAutoRangeMinimumSize(yrangeinterval);
        rangeAxis.setAutoRange(true);

    }
    if (this.useyrangeminmax) {
        rangeAxis.setRange(yrangemin, yrangemax);

    }

    resetDomainAxis(scope);

    final CategoryAxis domainAxis = ((CategoryPlot) this.chart.getPlot()).getDomainAxis();

    pp.setDomainGridlinePaint(axesColor);
    pp.setRangeGridlinePaint(axesColor);
    pp.setRangeCrosshairVisible(true);

    pp.getRangeAxis().setAxisLinePaint(axesColor);
    pp.getRangeAxis().setLabelFont(getLabelFont());
    pp.getRangeAxis().setTickLabelFont(getTickFont());
    if (textColor != null) {
        pp.getRangeAxis().setLabelPaint(textColor);
        pp.getRangeAxis().setTickLabelPaint(textColor);
    }
    if (getYTickUnit(scope) > 0) {
        ((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(getYTickUnit(scope)));
    }

    if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) {
        pp.getRangeAxis().setLabel(getYLabel(scope));
    }
    if (this.series_label_position.equals("yaxis")) {
        pp.getRangeAxis().setLabel(this.getChartdataset().getDataSeriesIds(scope).iterator().next());
        chart.getLegend().setVisible(false);
    }

    if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) {
        pp.getDomainAxis().setLabel(getXLabel(scope));
    }

    if (this.useSubAxis) {
        for (final String serieid : chartdataset.getDataSeriesIds(scope)) {
            ((SubCategoryAxis) domainAxis).addSubCategory(serieid);
        }

    }
    if (!this.getYTickLineVisible(scope)) {
        pp.setDomainGridlinesVisible(false);
    }

    if (!this.getYTickLineVisible(scope)) {
        pp.setRangeCrosshairVisible(false);

    }

    if (!this.getYTickValueVisible(scope)) {
        pp.getRangeAxis().setTickMarksVisible(false);
        pp.getRangeAxis().setTickLabelsVisible(false);

    }

}

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

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

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

    LOGGER.debug(debug, SOURCE + "--> ChartHelper.createChart()");

    MetadataHelper.showMetadataList(getMetadata(), SOURCE + " CHART METADATA --> ChartHelper.createChart()",
            LOADER_PROPERTIES.isMetadataDebug());

    channelselector.debugSelector(debug, SOURCE);

    // Creates TimeSeriesChart or XYLineChart to suit the dataset
    // The default renderer is an XYLineAndShapeRenderer
    jFreeChart = ChartHelper.createChart(primarydataset,
            ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug),
            getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit,
            channelselector, debug);
    if (jFreeChart != null) {
        // Customise the Chart for LogLin data if possible
        if ((hasLogarithmicMode()) && (!channelselector.isLinearMode())) {
            final XYPlot plot;
            final LogarithmicAxis axisLog;
            final String strAxisLabel;

            LOGGER.debug(debug, SOURCE + "Customise the Chart for LogLin data");

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

            // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis
            axisLog = new LogarithmicAxis(strAxisLabel);

            axisLog.setAllowNegativesFlag(true);
            axisLog.setLog10TickLabelsFlag(true);

            if ((canAutorange()) && (channelselector.isAutoranging())) {
                axisLog.setAutoRange(true);
                axisLog.configure();
                axisLog.autoAdjustRange();
            } else {
                axisLog.setRange(getLogarithmicFixedMinY(), getLogarithmicFixedMaxY());
                axisLog.configure();
                axisLog.autoAdjustRange();
            }

            plot = jFreeChart.getXYPlot();
            plot.setRangeAxis(INDEX_AXIS, axisLog);
            plot.setRangeAxisLocation(INDEX_AXIS, AxisLocation.BOTTOM_OR_LEFT);

            // Map the dataset to the axis
            plot.setDataset(INDEX_DATA, primarydataset);
            plot.mapDatasetToRangeAxis(INDEX_DATA, INDEX_AXIS);

            // Change the DateAxis format
            if (DatasetType.TIMESTAMPED.equals(datasettype)) {
                final DateAxis axisDate;

                // Customise the DomainAxis at index 0
                axisDate = (DateAxis) plot.getDomainAxis();

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

            // Now customise the data renderer to improve legend visibility
            ChartUIHelper.customisePlotRenderer(plot, 0);
        } else {
            final XYPlot plot;

            LOGGER.debug(debug, SOURCE + "Customise the Chart for Linear data");

            // Linear Mode

            // A default range suitable for display of dB
            ChartHelper.handleAutorangeForLinearMode(jFreeChart, channelselector, canAutorange(),
                    getLinearFixedMinY(), getLinearFixedMaxY(), debug);

            // Now customise the data renderer to improve legend visibility
            plot = jFreeChart.getXYPlot();
            ChartUIHelper.customisePlotRenderer(plot, 0);
        }
    } else {
        LOGGER.debug(debug, SOURCE + "Chart is NULL");
    }

    return (jFreeChart);
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputScatter.java

@Override
public void resetAxes(final IScope scope) {
    NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis();
    NumberAxis range2Axis = rangeAxis;//  w  w  w .  j av  a 2s  .c o  m
    boolean secondaxis = false;
    if (getUseSecondYAxis(scope)) {
        secondaxis = true;
        range2Axis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(1);
        if (range2Axis == null) {
            NumberAxis secondAxis = new NumberAxis("");
            ((XYPlot) this.chart.getPlot()).setRangeAxis(1, secondAxis);
            range2Axis = secondAxis;
            range2Axis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(1);
            range2Axis = formatYAxis(scope, range2Axis);

            ((XYPlot) this.chart.getPlot()).setRangeAxis(1, range2Axis);
        }
    }

    if (getX_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(domainAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((XYPlot) this.chart.getPlot()).setDomainAxis(logAxis);
        domainAxis = logAxis;
    }
    if (getY_LogScale(scope)) {
        LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        logAxis = (LogarithmicAxis) formatYAxis(scope, logAxis);
        ((XYPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;
    }
    if (secondaxis) {
        if (getY2_LogScale(scope)) {
            LogarithmicAxis logAxis = new LogarithmicAxis(range2Axis.getLabel());
            logAxis.setAllowNegativesFlag(true);
            logAxis = (LogarithmicAxis) formatYAxis(scope, logAxis);
            ((XYPlot) this.chart.getPlot()).setRangeAxis(1, logAxis);
            range2Axis = logAxis;
        }

    }

    if (!getUseXRangeInterval(scope) && !getUseXRangeMinMax(scope)) {
        domainAxis.setAutoRange(true);
    }

    if (this.getUseXRangeInterval(scope)) {
        domainAxis.setFixedAutoRange(getXRangeInterval(scope));
        domainAxis.setAutoRangeMinimumSize(getXRangeInterval(scope));
        domainAxis.setAutoRange(true);

    }
    if (this.getUseXRangeMinMax(scope)) {
        domainAxis.setRange(getXRangeMin(scope), getXRangeMax(scope));

    }
    if (this.getXTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setDomainGridlinePaint(this.tickColor);
        if (getXTickUnit(scope) > 0) {
            domainAxis.setTickUnit(new NumberTickUnit(getXTickUnit(scope)));
            ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(true);
        } else
            ((XYPlot) this.chart.getPlot())
                    .setDomainGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());

    } else {
        ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(false);

    }

    if (!getUseYRangeInterval(scope) && !getUseYRangeMinMax(scope)) {
        rangeAxis.setAutoRange(true);
    }

    if (this.getUseYRangeInterval(scope)) {
        rangeAxis.setFixedAutoRange(getYRangeInterval(scope));
        rangeAxis.setAutoRangeMinimumSize(getYRangeInterval(scope));
        rangeAxis.setAutoRange(true);
    }
    if (this.getUseYRangeMinMax(scope)) {
        rangeAxis.setRange(getYRangeMin(scope), getYRangeMax(scope));

    }
    if (this.getYTickLineVisible(scope)) {
        ((XYPlot) this.chart.getPlot()).setRangeGridlinePaint(this.tickColor);
        if (getYTickUnit(scope) > 0) {
            rangeAxis.setTickUnit(new NumberTickUnit(getYTickUnit(scope)));
            ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(true);
        } else
            ((XYPlot) this.chart.getPlot())
                    .setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());

    } else {
        ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false);

    }

    if (secondaxis) {
        if (!getUseY2RangeInterval(scope) && !getUseY2RangeMinMax(scope)) {
            range2Axis.setAutoRange(true);
        }

        if (this.getUseY2RangeInterval(scope)) {
            range2Axis.setFixedAutoRange(getY2RangeInterval(scope));
            range2Axis.setAutoRangeMinimumSize(getY2RangeInterval(scope));
            range2Axis.setAutoRange(true);
        }
        if (this.getUseY2RangeMinMax(scope)) {
            range2Axis.setRange(getY2RangeMin(scope), getY2RangeMax(scope));

        }
        if (this.getYTickLineVisible(scope)) {
            ((XYPlot) this.chart.getPlot()).setRangeGridlinePaint(this.tickColor);
            if (getY2TickUnit(scope) > 0) {
                range2Axis.setTickUnit(new NumberTickUnit(getY2TickUnit(scope)));
                ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(true);
            } else
                ((XYPlot) this.chart.getPlot())
                        .setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());

        } else {
            ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false);

        }

    }

    if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) {
        domainAxis.setLabel(getXLabel(scope));
    }
    if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) {
        rangeAxis.setLabel(getYLabel(scope));
    }
    if (secondaxis) {
        if (getY2Label(scope) != null && !getY2Label(scope).isEmpty()) {
            range2Axis.setLabel(getY2Label(scope));
        }

    }
    if (this.series_label_position.equals("none")) {
        (this.chart).getLegend().setVisible(false);
    }
    if (!this.getXTickValueVisible(scope)) {
        domainAxis.setTickMarksVisible(false);
        domainAxis.setTickLabelsVisible(false);

    }

}

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

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

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

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

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

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

        plot = jFreeChart.getXYPlot();

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

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

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

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

        axisDate = (DateAxis) plot.getDomainAxis();

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

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

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

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

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

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

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

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

    return (jFreeChart);
}