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

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

Introduction

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

Prototype

public XYItemRenderer getRenderer() 

Source Link

Document

Returns the renderer for the primary dataset.

Usage

From source file:org.matsim.contrib.dvrp.util.chart.RouteChartUtils.java

public static JFreeChart chartRoutes(List<? extends Vehicle> vehicles) {
    CoordDataset lData = new CoordDataset();

    for (int i = 0; i < vehicles.size(); i++) {
        Schedule<?> schedule = vehicles.get(i).getSchedule();
        lData.addSeries(Integer.toString(i), LinkSources.createLinkSource(schedule));
    }//w  w w . ja v  a 2  s.  com

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", lData, PlotOrientation.VERTICAL, true,
            true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        public String generateLabel(XYDataset dataset, int series, int item) {
            return ((CoordDataset) dataset).getText(series, item);
        }
    });

    for (int i = 1; i <= vehicles.size(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesItemLabelsVisible(i, true);
    }

    return chart;
}

From source file:org.jfree.chart.demo.TimeSeriesChartDemo1.java

/**
 * Creates a chart.//from  w w  w  . j ava  2 s.com
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setDefaultShapesVisible(true);
        renderer.setDefaultShapesFilled(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}

From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart./*from w  ww  .j a v  a 2  s .c  o  m*/
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    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));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart./*from ww w.j  a v a2s  .co  m*/
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    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));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Day(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    // axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Day(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Day(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:org.matsim.contrib.dvrp.util.chart.RouteCharts.java

public static JFreeChart chartRoutes(Collection<? extends Vehicle> vehicles) {
    CoordDataset lData = new CoordDataset();
    int i = 0;// w  w w . j  a va  2  s  .c o  m
    for (Vehicle v : vehicles) {
        Schedule schedule = v.getSchedule();
        lData.addSeries(Integer.toString(i++), ScheduleCoordSources.createCoordSource(schedule));
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", lData, PlotOrientation.VERTICAL, true,
            true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        public String generateLabel(XYDataset dataset, int series, int item) {
            return ((CoordDataset) dataset).getText(series, item);
        }
    });

    for (int j = 1; j <= vehicles.size(); j++) {
        renderer.setSeriesShapesVisible(j, true);
        renderer.setSeriesLinesVisible(j, true);
        renderer.setSeriesItemLabelsVisible(j, true);
    }

    return chart;
}

From source file:org.matsim.contrib.util.timeprofile.TimeProfileCharts.java

public static JFreeChart chartProfile(DefaultTableXYDataset dataset, ChartType type) {
    JFreeChart chart;//from   w w  w .j ava2 s  .  c om
    switch (type) {
    case Line:
        chart = ChartFactory.createXYLineChart("TimeProfile", "Time [h]", "Values", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        break;

    case StackedArea:
        chart = ChartFactory.createStackedXYAreaChart("TimeProfile", "Time [h]", "Values", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        break;

    default:
        throw new IllegalArgumentException();
    }

    XYPlot plot = chart.getXYPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRange(true);

    XYItemRenderer renderer = plot.getRenderer();
    for (int s = 0; s < dataset.getSeriesCount(); s++) {
        renderer.setSeriesStroke(s, new BasicStroke(2));
    }

    return chart;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static void setXYSeriesColors(JFreeChart chart, ChartData chartData) {
    if (chart.getPlot() instanceof XYPlot && chartData.getColors() != null) {
        XYPlot plot = (XYPlot) chart.getPlot();
        String[] colors = chartData.getColors().split(",");
        for (int i = 0; i < colors.length; i++) {
            plot.getRenderer().setSeriesPaint(i, ChartUtils.getColor(colors[i].trim()));
        }/*from  w w  w . j  a  va  2  s  . com*/
    }
}

From source file:org.jfree.chart.demo.MultipleAxisDemo4.java

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset("March 2007", 100D, new Day(1, 3, 2007), 31);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 4", "Date", "Value",
            xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setOrientation(PlotOrientation.VERTICAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy"));
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.red);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickLabelPaint(Color.red);
    DateAxis dateaxis1 = new DateAxis("Date");
    dateaxis1.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy"));
    xyplot.setDomainAxis(1, dateaxis1);//from   www .j a v  a  2s .  c o m
    xyplot.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT);
    NumberAxis numberaxis1 = new NumberAxis("Value");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setTickLabelPaint(Color.blue);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    XYDataset xydataset1 = createDataset("July 2007", 1000D, new Day(1, 7, 2007), 31);
    xyplot.setDataset(1, xydataset1);
    xyplot.mapDatasetToDomainAxis(1, 1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(1, xylineandshaperenderer);
    return jfreechart;
}

From source file:org.matsim.contrib.dvrp.util.chart.RouteChartUtils.java

public static JFreeChart chartRoutesByStatus(List<? extends Vehicle> vehicles) {
    CoordDataset nData = new CoordDataset();

    for (int i = 0; i < vehicles.size(); i++) {
        Schedule<?> schedule = vehicles.get(i).getSchedule();
        Map<TaskStatus, CoordSource> vsByStatus = createLinkSourceByStatus(schedule);
        nData.addSeries(i + "-PR", vsByStatus.get(TaskStatus.PERFORMED));
        nData.addSeries(i + "-ST", vsByStatus.get(TaskStatus.STARTED));
        nData.addSeries(i + "-PL", vsByStatus.get(TaskStatus.PLANNED));
    }// w w w.j a va  2s . c om

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", nData, PlotOrientation.VERTICAL,
            false, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new LabelGenerator());

    Paint[] paints = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE;
    Shape[] shapes = DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;

    for (int i = 0; i < vehicles.size(); i++) {
        int s = 3 * i;

        renderer.setSeriesItemLabelsVisible(s + 1, true);
        renderer.setSeriesItemLabelsVisible(s + 2, true);
        renderer.setSeriesItemLabelsVisible(s + 3, true);

        renderer.setSeriesShapesVisible(s + 1, true);
        renderer.setSeriesShapesVisible(s + 2, true);
        renderer.setSeriesShapesVisible(s + 3, true);

        renderer.setSeriesLinesVisible(s + 1, true);
        renderer.setSeriesLinesVisible(s + 2, true);
        renderer.setSeriesLinesVisible(s + 3, true);

        renderer.setSeriesPaint(s + 1, paints[(i + 1) % paints.length]);
        renderer.setSeriesPaint(s + 2, paints[(i + 1) % paints.length]);
        renderer.setSeriesPaint(s + 3, paints[(i + 1) % paints.length]);

        renderer.setSeriesShape(s + 1, shapes[(i + 1) % shapes.length]);
        renderer.setSeriesShape(s + 2, shapes[(i + 1) % shapes.length]);
        renderer.setSeriesShape(s + 3, shapes[(i + 1) % shapes.length]);

        renderer.setSeriesStroke(s + 2, new BasicStroke(3));
        renderer.setSeriesStroke(s + 3, new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1,
                new float[] { 5f, 5f }, 0));
    }

    return chart;
}

From source file:pisco.batch.visu.BatchingChartFactory.java

public static JFreeChart createWFlowChart(Batch[] batches, String title, int capacity) {
    final XYPlot objPlot = createWFlowtimePlot(batches);
    final JFreeChart chart = createCombinedChart(title, createBatchPlot(batches, capacity), objPlot);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) objPlot.getRenderer();
    renderer.setSeriesPaint(0, B_RED);/*from w  w  w .ja va2  s. c  o m*/
    renderer.setSeriesFillPaint(0, B_RED);
    return chart;
}