Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseSeriesVisibleInLegend

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseSeriesVisibleInLegend

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseSeriesVisibleInLegend.

Prototype

public void setBaseSeriesVisibleInLegend(boolean visible) 

Source Link

Document

Sets the base visibility in the legend and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo2.java

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {
    //DomainAxis//  w  w w .j  av a  2 s .  c  o  m
    DateAxis timeAxis = new DateAxis("");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
    //RangeAxis
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer

    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYURLGenerator urlGenerator = null;
    //            urlGenerator = new StandardXYURLGenerator();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    //AbstractRenderer.dataBoundsIncludesVisibleSeriesOnly
    renderer.setDataBoundsIncludesVisibleSeriesOnly(false);
    renderer.setBaseSeriesVisibleInLegend(true);
    //Plot
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null) {
        private static final long serialVersionUID = 1L;

        //            public void rendererChanged(RendererChangeEvent event) {
        //                // if the event was caused by a change to series visibility, then
        //                // the axis ranges might need updating...
        //                if (event.getSeriesVisibilityChanged()) {
        ////                    configureDomainAxes();
        ////                    configureRangeAxes();
        //                }
        //                fireChangeEvent();
        //            }
    };
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(plotBackgroundPaint);
    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.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    valueAxis.setAutoRange(false);
    timeAxis.setAutoRange(false);
    return chart;
}

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

/**
 * @param hour A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 a.m. ...
 *///from   ww  w . j  a  va  2 s. c o  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 = "Volumes " + (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.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;/*from ww  w . jav a2  s. 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 ww  . j a v a2 s . 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  . j  a  va2 s  .  com
 *            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:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartTime() {
    TreeMap<String, List<TestStepInstance>> s = getGroupedSteps(getFilteringIterator());
    if (s == null || s.size() == 0) {
        return null;
    }// ww w  .j  a  v a 2  s  .  co  m
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (Iterator<String> en = s.keySet().iterator(); en.hasNext();) {
        String groupName = en.next();
        List<TestStepInstance> stps = s.get(groupName);
        //            TimeSeries pop = new TimeSeries(groupName, Millisecond.class);
        TimeSeries pop = new TimeSeries(groupName);
        for (Iterator<TestStepInstance> it = stps.iterator(); it.hasNext();) {
            TestStepInstance step = it.next();
            Number num = getNumber(step);
            if (num != null) {
                switch (chartMode) {
                case STEP_TIME:
                    pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class,
                            new Date(step.getStartTime()), TimeZone.getDefault()), num);
                    break;
                case SEQUENCE_TIME:
                    //                            pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date(step.getTestSequenceInstance().getStartTime()), RegularTimePeriod.DEFAULT_TIME_ZONE), num);
                    pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class,
                            new Date(step.getTestSequenceInstance().getCreateTime()), TimeZone.getDefault()),
                            num);
                    break;
                }
            }
        }
        dataset.addSeries(pop);
    }
    JFreeChart chart = null;
    switch (chartMode) {
    case STEP_TIME:
        chart = ChartFactory.createTimeSeriesChart(null, "Step Started Time", getValueString(), dataset,
                isGrouping(), true, false);
        break;
    case SEQUENCE_TIME:
        chart = ChartFactory.createTimeSeriesChart(null, "Sequence Started Time", getValueString(), dataset,
                isGrouping(), true, false);
        break;
    }
    chart.setBackgroundPaint((Paint) UIManager.get("Panel.background"));

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    XYLineAndShapeRenderer renderer5 = new XYLineAndShapeRenderer();
    renderer5.setBaseSeriesVisibleInLegend(false);
    plot.setRenderer(renderer5);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairVisible(true);
    //        chart.setTitle(valueName);
    placeLimitMarkers(plot, true);

    //renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer5.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

    /* coloring */
    if (isCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            Color c = ChartCategories.getColor(i);
            for (int j = 0; j < dataset.getSeriesCount(); j++) {
                TimeSeries ts = dataset.getSeries(j);
                if (ts.getKey().equals(groupName)) {
                    renderer5.setSeriesPaint(j, c);
                }
            }
        }
    } else {
        renderer5.setSeriesPaint(0, ChartCategories.getColor(0));
    }

    //        chart.addProgressListener(new ChartProgressListener() {
    //
    //            public void chartProgress(final ChartProgressEvent progress) {
    //                SwingUtilities.invokeLater(
    //                        new Runnable() {
    //
    //                            @Override
    //                            public void run() {
    //
    //                                System.out.println("progress:" + progress + " " + progress.getType());
    //                                if (progress.getType() == ChartProgressEvent.DRAWING_FINISHED) {
    //                                    if (plot != null) {
    //                                        if (plot.isDomainCrosshairVisible() && plot.isDomainCrosshairLockedOnData()) {
    ////                            System.out.println("getDomainCrosshairValue:" + plot.getDomainCrosshairValue());
    //                                            double xx = plot.getDomainCrosshairValue();
    //                                            if (xx != 0.0) {
    //                                                long x = (long) xx;
    //                                                System.out.println(new Date(x));
    //                                                for (TestStepInstance step : testStepInstances.getSteps()) {
    //                                                    if (step.getStartTime() != null && step.getStartTime().equals(x)) {
    //                                                        testStepInstances.selectStep(step);
    //                                                    }
    //                                                }
    //                                                System.out.println(new Date(x));
    //                                            }
    //                                        }
    ////                        if (plot.isRangeCrosshairVisible()) {
    ////                            System.out.println("getRangeCrosshairValue:" + plot.getRangeCrosshairValue());
    ////                        }
    //                                    }
    //                                }
    //                            }
    //                        });
    //            }
    //        });

    //        chart.addChangeListener(new ChartChangeListener() {
    //
    //            public void chartChanged(ChartChangeEvent event) {
    //                System.out.println("event:" + event);
    //                if (event != null) {
    ////                    JFreeChart chart = event.getChart();
    ////                    System.out.println("chart:" + chart);
    ////                    if (chart != null) {
    ////                        System.out.println("title:" + event.getChart().getTitle());
    ////                    }
    //                    System.out.println("type:" + event.getType());
    //                    if (plot != null) {
    //                        if (plot.isDomainCrosshairVisible()) {
    //                            System.out.println("getDomainCrosshairValue:" + plot.getDomainCrosshairValue());
    //                            long x = (long) plot.getDomainCrosshairValue();
    //                            for (TestStepInstance step : testStepInstances.getSteps()) {
    //                                if (step.getStartTime() != null && step.getStartTime().equals(x)) {
    //                                    testStepInstances.selectStep(step);
    //                                }
    //                            }
    //                            System.out.println(new Date(x));
    //                        }
    //                        if (plot.isRangeCrosshairVisible()) {
    //                            System.out.println("getRangeCrosshairValue:" + plot.getRangeCrosshairValue());
    //                        }
    //                    }
    //                }
    //            }
    //        });
    chart.setTextAntiAlias(false);
    return chart;
}

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartDistribution(boolean horizontal) {
    //        System.out.println("Min: " + minValue());
    //        System.out.println("Max: " + maxValue());
    XYIntervalSeriesCollection datasetDistribution = createIntervalXYDatasetDistribution(horizontal);
    XYSeriesCollection dataset2 = createXYDatasetGauss(horizontal);
    // create the chart...
    NumberAxis xAxis = new NumberAxis(getValueString());
    xAxis.setAutoRangeIncludesZero(false);
    //        NumberAxis yAxis = new NumberAxis("Distribution");
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(true);
    //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer = new MyBarRenderer();
    XYPlot plot = new XYPlot(datasetDistribution, xAxis, yAxis, renderer);
    plot.setOrientation(horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping());
    chart.setBackgroundPaint((Paint) UIManager.get("Panel.background"));
    //        plot.setBackgroundPaint(Color.white);
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    StandardXYItemLabelGenerator itemlabels = new StandardXYItemLabelGenerator();
    renderer.setBaseItemLabelGenerator(itemlabels);
    renderer.setBaseItemLabelsVisible(true);
    plot.setDataset(1, dataset2);//from www. j  a  va 2s  .c  o  m
    plot.mapDatasetToRangeAxis(1, 1);
    //        ValueAxis domainAxis = plot.getDomainAxis();
    //domainAxis.setCategoryLabelPositions(horizontal?CategoryLabelPositions.STANDARD:CategoryLabelPositions.UP_90);
    ValueAxis axis2 = new NumberAxis("Gaussian");
    plot.setRangeAxis(1, axis2);
    axis2.setVisible(false);
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    //renderer2.setShapesVisible(false);
    //renderer2.setSeriesVisibleInLegend(false);
    renderer2.setBaseSeriesVisibleInLegend(false);
    //renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    renderer.setUseYInterval(true);
    renderer.setBaseSeriesVisibleInLegend(false);
    /* coloring */
    Color c;
    if (isMultipleCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            c = ChartCategories.getColor(i);
            for (int j = 0; j < datasetDistribution.getSeriesCount(); j++) {
                XYIntervalSeries s = datasetDistribution.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker());
                    renderer.setSeriesPaint(j, gp);
                }
            }
            for (int j = 0; j < dataset2.getSeriesCount(); j++) {
                XYSeries s = dataset2.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    renderer2.setSeriesPaint(j, c);
                    renderer2.setSeriesShapesVisible(j, false);
                    renderer2.setSeriesStroke(j, myStroke);
                }
            }
        }
        c = Color.black;
    } else {
        c = ChartCategories.getColor(0);
        GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker());
        renderer.setSeriesPaint(0, gp);
    }
    renderer2.setSeriesPaint(0, c);
    renderer2.setSeriesShapesVisible(0, false);
    renderer2.setSeriesStroke(0, myStroke);

    placeLimitMarkers(plot, false);
    //        renderer.setAutoPopulateSeriesOutlinePaint(true);
    //        renderer.setBaseOutlinePaint(Color.black);
    //        renderer.setSeriesOutlinePaint(0, Color.black, true);
    //        renderer.setDrawBarOutline(true);

    renderer.setHighlightedItem(0, 0);
    yAxis.setAutoRange(false);
    yAxis.setAutoRange(true);
    xAxis.setRange(leftValue(0), rightValue(numberOfCategories - 1));
    chart.setTextAntiAlias(false);
    return chart;
}

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartValues(Iterator<TestStepInstance> values) {
    if (values == null || !values.hasNext()) {
        return null;
    }//  ww w  .j a v  a 2  s.  c  o  m

    XYSeriesCollection dataset = new XYSeriesCollection();
    int count = 0;
    TreeMap<String, XYSeries> map = new TreeMap<String, XYSeries>();
    while (values.hasNext()) {
        TestStepInstance step = values.next();
        Number num = getNumber(step);
        if (num != null) {
            String groupName = getGroupName(step);
            XYSeries pop = map.get(groupName);
            if (pop == null) {
                pop = new XYSeries(groupName);
                map.put(groupName, pop);
            }

            pop.add(++count, num.doubleValue());
        }

    }
    for (Iterator<XYSeries> it = map.values().iterator(); it.hasNext();) {
        dataset.addSeries(it.next());
    }

    //        NumberAxis xAxis = new NumberAxis("#");
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(getValueString());
    yAxis.setAutoRangeIncludesZero(false);
    XYLineAndShapeRenderer renderer6 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer6);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairVisible(true);
    renderer6.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer6.setBaseSeriesVisibleInLegend(false);

    //        StandardXYItemLabelGenerator itemlabels=new StandardXYItemLabelGenerator();
    //        renderer.setBaseItemLabelGenerator(itemlabels);
    //        renderer.setBaseItemLabelsVisible(true);

    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping());
    //chart.setTitle(title);
    placeLimitMarkers(plot, true);
    /* coloring */
    if (isCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            Color c = ChartCategories.getColor(i);
            for (int j = 0; j < dataset.getSeriesCount(); j++) {
                XYSeries s = dataset.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    renderer6.setSeriesPaint(j, c);
                }
            }
        }
    } else {
        renderer6.setSeriesPaint(0, ChartCategories.getColor(0));
    }
    chart.setTextAntiAlias(false);
    return chart;
}

From source file:CGgui.java

public void addMinima(double value) {
    //updata dataset and graph
    if (value != -1) {
        //remove previous minima for this number of CGs
        for (int i = 0; i < minimadataset.getItemCount(); i++) {
            if (minimadataset.getYValue(0, i) == CurrCG) {
                minimadataset.remove(minimadataset.getX(0, i), (String) key, true);
                break;
            }/*  w w w. j  a va2 s  .co m*/
        }

        //add new minima
        minimadataset.add(value, (double) CurrCG, (String) key);
    } else
        return;

    //get plot
    XYPlot xyplot = minchart.getXYPlot();
    minchart.clearSubtitles();

    //set render options
    XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();

    Shape shape = xyplot.getRenderer().getSeriesShape(0);
    renderer1.setSeriesLinesVisible(0, false);
    renderer1.setSeriesPaint(0, Color.RED);
    renderer1.setSeriesShape(0, shape);
    if (minimadataset.getItemCount() > 1) {
        renderer2.setSeriesLinesVisible(0, true);
        renderer2.setSeriesShapesVisible(0, false);
        renderer2.setBaseSeriesVisibleInLegend(false);
        renderer2.setSeriesPaint(0, Color.BLUE);
    }

    //get regression
    LineFunction2D localregline = null;
    XYDataset regseries;
    if (minimadataset.getItemCount() > 1) {
        //create the regression
        double[] reg = Regression.getOLSRegression(minimadataset, 0);
        //looking for x values so put x in terms of y
        //y = a + bx     for local
        //x = y/b - a/b  for global
        if (DEBUG)
            PrintText("Regression: y = " + reg[0] + " + " + reg[1] + "x\n");

        //global (in terms of y)
        regLine = new LineFunction2D(-reg[0] / reg[1], 1 / reg[1]);

        //local (in terms of x)
        localregline = new LineFunction2D(reg[0], reg[1]);
        regseries = DatasetUtilities.sampleFunction2D(localregline, minimadataset.getDomainLowerBound(false),
                minimadataset.getDomainUpperBound(false), 2, "Linear Regression");

        //plot line
        xyplot.setDataset(1, regseries);
        xyplot.setRenderer(1, renderer2);
        minchart.addSubtitle(0, new TextTitle("Regression: y = " + reg[0] + " + " + reg[1] + "x"));
    }

    xyplot.setDataset(0, minimadataset);
    xyplot.setRenderer(0, renderer1);

    //f.pack();

    //System.gc();
}