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

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

Introduction

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

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

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

Usage

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

/**
 * Creates a XY graph with symbolic value on Y axis.
 * //from   ww w  .ja va  2s.  c  o  m
 * @param title
 *           the chart title.
 * @param xAxisLabel
 *           the x-axis label.
 * @param yAxisLabel
 *           the y-axis label.
 * @param data
 *           the data.
 * @param legend
 *           a flag controlling whether or not the legend is created for the chart.
 * @return the chart.
 */
public static JFreeChart createYSymbolicPlot(final String title, final String xAxisLabel,
        final String yAxisLabel, final XYDataset data, final boolean legend) {

    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data).getYSymbolicValues());

    final XYPlot plot = new XYPlot(data, valueAxis, symbolicAxis, null);
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES,
            new SymbolicXYItemLabelGenerator());
    plot.setRenderer(renderer);
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}

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

private static JFreeChart createXYStepChart(XYDataset dataset) {

    DateAxis xAxis = new DateAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }//from w  w  w  . j a v  a 2 s .com

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart("XYStep Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    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);

    xAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));

    return chart;
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel,
        int pointRadius, int lineThickness, ColorTheme theme) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL,
            true, false, false);/*  w  w w  .  j  a v  a 2 s. c  o m*/

    formatColorTheme(chart, theme);

    XYPlot plot = (XYPlot) chart.getPlot();
    Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    Color[] colors = generateJetSpectrum(data.getSeriesCount());
    for (int i = 0; i < data.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness));
        plot.getRenderer().setSeriesShape(i, icon);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true);
        plot.getRenderer().setSeriesPaint(i, colors[i]);
    }

    LegendTitle legend = chart.getLegend();
    Font legendFont = legend.getItemFont();
    float legendFontSize = legendFont.getSize();
    Font newLegendFont = legendFont.deriveFont(legendFontSize * 0.6f);
    legend.setItemFont(newLegendFont);

    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Font domainAxisLabelFont = domainAxis.getLabelFont();
    float domainAxisLabelFontSize = domainAxisLabelFont.getSize();
    domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f));

    Font domainAxisTickLabelFont = domainAxis.getTickLabelFont();
    float domainAxisTickLabelFontSize = domainAxisTickLabelFont.getSize();
    domainAxis.setTickLabelFont(domainAxisTickLabelFont.deriveFont(domainAxisTickLabelFontSize * 0.6f));

    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    Font rangeAxisLabelFont = rangeAxis.getLabelFont();
    float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize();
    rangeAxis.setLabelFont(rangeAxisLabelFont.deriveFont(rangeAxisLabelFontSize * 0.6f));

    Font rangeAxisTickLabelFont = rangeAxis.getTickLabelFont();
    float rangeAxisTickLabelFontSize = rangeAxisTickLabelFont.getSize();
    rangeAxis.setTickLabelFont(rangeAxisTickLabelFont.deriveFont(rangeAxisTickLabelFontSize * 0.6f));

    return chart;
}

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

private static JFreeChart createXYStepAreaChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }/*  w w w. j ava 2 s .  c om*/

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator,
            urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart("XYStepArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    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);

    yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:umberto.WeightedClusterCoefficient.ChartUtils.java

public static void decorateChart(JFreeChart chart) {
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 3, 3));
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainGridlinePaint(java.awt.Color.GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.GRAY);
    plot.setRenderer(renderer);
}

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

public static XYPlot createWFlowtimePlot(Batch[] batches) {
    ValueAxis timeAxis = new DateAxis("");
    NumberAxis valueAxis = new NumberAxis("Cum. WFlow");
    valueAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(createWFlowtimeDataset(batches), timeAxis, valueAxis, null);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    renderer.setBaseToolTipGenerator(new WFlowLabelToolTipGenerator(batches));
    plot.setRenderer(renderer);
    return plot;//ww  w. j  av  a  2  s . c o m
}

From source file:utils.Graficos_old.java

public static JFreeChart GraficoLinhas(List<CarCapContas> pagar, List<CarCapContas> receber, String titulo) {

    XYSeries series1 = new XYSeries("Pagar");

    //        CarCapContas contasPagar = new CarCapContas();
    for (CarCapContas contasPagar : pagar) {

        series1.add(contasPagar.getContaValorTotal(), contasPagar.getContaDataEmissao().getMonth());

    }/*ww w  .  ja v  a  2  s.  c  o m*/

    XYSeries series2 = new XYSeries("Receber");

    for (CarCapContas contasReceber : receber) {

        series2.add(contasReceber.getContaValorTotal(), contasReceber.getContaDataEmissao().getMonth());

    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(series1);
    dataset.addSeries(series2);

    JFreeChart chart = ChartFactory.createXYLineChart(titulo, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

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

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;

}

From source file:max.hubbard.Factoring.Graphing.java

private static JFreeChart createChart(final XYDataset dataset, String equation) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(equation, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from w  w w  .j a  v  a  2  s .c o m*/

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

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //              legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(-50, 50));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java

public static void plotLineChart(Map<String, List<Double>> series, String filename, String title, String labelX,
        String labelY) throws IOException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (String label : series.keySet()) {
        XYSeries data = new XYSeries(label);
        int t = 0;
        for (Double d : series.get(label)) {
            data.add(t, d);//from  w w w.  ja  v  a 2 s  .c o m
            t++;
        }
        dataset.addSeries(data);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(title, labelX, labelY, dataset, PlotOrientation.VERTICAL,
            true, true, false);
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);
    ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768);
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("YIntervalChartDemo2", "Date", "Value",
            intervalxydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);//from ww w .  jav a 2  s .  com
    xyplot.setRangePannable(true);
    xyplot.setDomainAxis(new DateAxis("Date"));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    xyerrorrenderer.setBaseLinesVisible(true);
    xyerrorrenderer.setUseFillPaint(true);
    xyerrorrenderer.setBaseFillPaint(Color.white);
    xyplot.setRenderer(xyerrorrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}