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.RouteCharts.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));
    }//  ww w.j  a  v  a 2  s . co  m

    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:grafici.FattureTimeSeriesChart.java

/**
 * Creates a chart./*  w w w  . j  a v a2s .  c  om*/
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(titolo, // title
            "Date", // x-axis label
            "Quantit", // 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.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

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

    return chart;

}

From source file:com.mxgraph.examples.swing.chart.TimeSeriesChartDemo1.java

/**
 * Creates a chart./*from   w  w w. j  a v a2  s  .co m*/
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
public static JFreeChart createChart(XYDataset dataset, String name) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "Date", // x-axis label
            "Value", // 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.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator());
        renderer.setBaseItemLabelsVisible(true);
        // 
        renderer.setItemLabelsVisible(true);
        // 
        renderer.setBaseShapesVisible(true);
        // 
        renderer.setBaseShapesFilled(true);

        //  renderer.setLegendItemLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));

    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"/*"yyyy-MM-dd HH:mm:ss"*/));

    chart.getTitle().setFont(new Font("", Font.BOLD, 15));
    chart.getLegend().setItemFont(new Font("", Font.BOLD, 15));
    //
    plot.getRangeAxis().setLabelFont(new Font("", Font.BOLD, 15));
    //
    chart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    //
    plot.getDomainAxis().setTickLabelFont(new Font("", 1, 15));
    //
    plot.getDomainAxis().setLabelFont(new Font("", 1, 12));

    return chart;

}

From source file:grafici.MediciTimeSeriesChart.java

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

    JFreeChart chart = ChartFactory.createTimeSeriesChart(titolo, // title
            "Date", // x-axis label
            "Occorrenze", // 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.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

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

    return chart;

}

From source file:bullioneconomy.bullionchart.java

/**
 * Creates a chart./*from   w w  w  . j ava2  s . c  om*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Gold Price in Recent Years", // title
            "Date", // x-axis label
            "Price Per 10g", // 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:com.ace.capitalflows.ui.frame.chart.NianYdChart.java

/**
 * Creates a chart./*from   www  .j  a v a2 s  .c  o  m*/
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("ZhongGuoGuoJiShouZhiPingHeBiao(NianDuCeSuan)", // title
            "NianYd", // x-axis label
            "YiMeiYuan", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

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

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

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

    return chart;

}

From source file:org.encog.workbench.dialogs.activation.EquationPanel.java

/**
 * Creates a line chart using the data from the supplied dataset.
 *
 * @param dataset  the dataset./*ww w  .  ja  v a  2 s.  c o m*/
 *
 * @return The chart.
 */
public static JFreeChart createChart(XYDataset dataset, ActivationFunction activation, boolean normal) {

    String title;

    if (normal) {
        title = activation.getClass().getSimpleName();
    } else {
        if (activation.hasDerivative()) {
            title = "Derv of " + activation.getClass().getSimpleName();
        } else {
            title = "NO Derv of " + activation.getClass().getSimpleName();
        }
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "input (x)", "output (y)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();

    if (normal) {

        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainPannable(true);
        plot.setRangePannable(true);
        ValueAxis xAxis = plot.getDomainAxis();
        xAxis.setLowerMargin(0.0);
        xAxis.setUpperMargin(0.0);
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        r.setDrawSeriesLineAsPath(true);
        r.setSeriesStroke(0, new BasicStroke(1.5f));
        r.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 6.0f, 4.0f }, 0.0f));
        r.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 6.0f, 4.0f, 3.0f, 3.0f }, 0.0f));
        r.setSeriesStroke(3, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 4.0f, 4.0f }, 0.0f));
    }

    return chart;
}

From source file:st.jigasoft.dbutil.util.ReportTheme.java

public static void crescentTheme(JFreeChart chart, String... lineNames) {

    XYPlot plot = (XYPlot) chart.getPlot();

    chart.setBackgroundPaint(Color.white);

    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.setBaseShapesVisible(true);
        renderer.setStroke(new BasicStroke(3));
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }//from ww  w.  java2s  .c o  m

    DateAxis axis = (DateAxis) plot.getDomainAxis();

    /*
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), 
        Color.decode("#121E31"), new Point(400, 200), Color.DARK_GRAY));
            
            
    plot.setBackgroundPaint(null);
    //plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);
            
    int iCount = 0;
    // use gradients and white borders for the section colours
    for(Object s : lineNames)
    {
             
    //          plot.setDomainGridlinePaint(new PrintColorUIResource(25, Color.CYAN)));//s.toString(), createGradientPaint(new Color(200, 200, 255), colorItems(iCount ++)));
    if(iCount == MAX_COLUNS_COLOR) iCount = 0;
    }
            
               
            
    //        // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", 
        new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
        */
}

From source file:com.ace.capitalflows.ui.frame.chart.NianJdChart.java

/**
 * Creates a chart./* w  ww.j ava2  s  .  c  o m*/
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("ZhongGuoGuoJiShouZhiPingHeBiao(NianDuCeSuan)", // title
            "NianJd", // x-axis label
            "YiMeiYuan", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

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

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

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

    return chart;

}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset1();
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit",
            xydataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.mapDatasetToRangeAxis(1, 1);/* w  w  w. j a va 2s  . c  om*/
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D,
            167.30000000000001D, -0.78539816339744828D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    xypointerannotation.setPaint(Color.red);
    xypointerannotation.setArrowPaint(Color.red);
    xylineandshaperenderer.addAnnotation(xypointerannotation);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D,
            613.20000000000005D, 1.5707963267948966D);
    xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
    xylineandshaperenderer1.addAnnotation(xypointerannotation1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}