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:de.iteratec.visualizationmodel.jfreechart.ChartFactory.java

public JFreeChart createXYStepChart(XYDataset dataset) {
    XYToolTipGenerator toolTipGenerator = !showTooltips ? null : new StandardXYToolTipGenerator();
    XYURLGenerator urlGenerator = !showUrls ? null : new StandardXYURLGenerator();
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, (ValueAxis) xAxis, (ValueAxis) yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);//  ww  w . j a  va 2s . c  o m
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(5.0f));
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
    THEME.apply(chart);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL,/* ww w  .java  2  s.  com*/
            // !legendPanelOn,
            false, // no legend
            true, false);

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo2.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, // !legendPanelOn,
            true, false);//from  w  w w  .  ja  v  a 2  s . co  m

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // setXSummary(dataset);  //X  is time
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:com.sixrr.metrics.ui.charts.HistogramDialog.java

private JFreeChart createChart(IntervalXYDataset dataset, boolean isIntegral) {
    final String title = getTitle();
    final NumberAxis xAxis = new NumberAxis();
    if (isIntegral) {
        xAxis.setTickUnit(new NumberTickUnit(1.0));
    }/*from   www.  ja  v a 2 s  .co  m*/
    if (metricType == MetricType.Ratio || metricType == MetricType.RecursiveRatio) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }

    final XYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator();

    final XYItemRenderer renderer = new XYBarRenderer();
    renderer.setToolTipGenerator(tooltipGenerator);
    renderer.setURLGenerator(null);

    final ValueAxis yAxis = new NumberAxis();
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:daylightchart.sunchart.chart.SunChart.java

/**
 * Creates the daylight chart./* w w  w.  j av a2 s .  com*/
 */
private void createChart() {

    setBackgroundPaint(Color.white);

    final XYPlot plot = getXYPlot();

    plot.setRenderer(new StandardXYItemRenderer());
    plot.setBackgroundPaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    createAzimuthAxis(plot);
    createAltitudeAxis(plot);

    createBandsInPlot(plot);

}

From source file:net.sf.statcvs.output.xml.chart.TimeLineChart.java

/**
 * @param filename/*from   ww w.ja  v  a2s.  c  o m*/
 * @param title
 */
public TimeLineChart(String filename, String title) {
    super(filename, title);

    Paint[] colors = new Paint[1];
    colors[0] = Color.blue;

    tsc = new TimeSeriesCollection();
    //collection.addSeries(createTimeSeries(timeline));

    //String range = timeline.getRangeLabel();
    String domain = I18n.tr("Date");

    setChart(ChartFactory.createTimeSeriesChart(Settings.getProjectName(), I18n.tr("Date"), rangeLabel,
            (XYDataset) tsc, true, true, false));

    //getChart().getPlot().setSeriesPaint(colors);

    XYPlot plot = getChart().getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setVerticalTickLabels(true);
    plot.setRenderer(new XYStepRenderer());
}

From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java

/**
 * @param folderToWrite Folder to write the resulted charts.
 * @param plots Collections of plots.// w w  w .  j  a  va2s.  co  m
 * @param infoMap Map with additional plot info.
 * @param mode Generation mode.
 * @throws Exception If failed.
 */
private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots,
        Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception {
    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    int idx = -1;

    while (true) {
        idx++;

        DefaultXYDataset dataSet = new DefaultXYDataset();

        List<JFreeChartPlotInfo> infoList = new ArrayList<>();

        String xAxisLabel = "";
        String yAxisLabel = "";
        String plotName = "";

        int cnt = 0;

        for (List<PlotData> plotData0 : plots) {
            if (plotData0.size() <= idx)
                continue;

            PlotData plotData = plotData0.get(idx);

            dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data);

            xAxisLabel = plotData.xAxisLabel;
            yAxisLabel = plotData.yAxisLabel;
            plotName = plotData.plotName();

            infoList.add(info(plotData.series(), mode));
        }

        if (infoList.isEmpty())
            break;

        JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet,
                PlotOrientation.VERTICAL, false, false, false);

        AxisSpace as = new AxisSpace();

        as.add(150, RectangleEdge.LEFT);

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

        BasicStroke stroke = new BasicStroke(1);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(WHITE);
        plot.setRangeGridlinePaint(GRAY);
        plot.setDomainGridlinePaint(GRAY);
        plot.setFixedRangeAxisSpace(as);
        plot.setOutlineStroke(stroke);

        for (int i = 0; i < infoList.size(); i++) {
            Color color = PLOT_COLORS[i % PLOT_COLORS.length];

            renderer.setSeriesPaint(i, color);
            renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness.

            infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2));
        }

        ValueAxis axis = plot.getRangeAxis();

        Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5);

        axis.setTickLabelFont(font);
        axis.setLabelFont(font);
        plot.getDomainAxis().setTickLabelFont(font);
        plot.getDomainAxis().setLabelFont(font);

        chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30)));

        File res = new File(folderToWrite, plotName + ".png");

        ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info);

        infoMap.put(res.getAbsolutePath(), infoList);

        println("Chart is saved to file: ", res);
    }
}

From source file:com.sixrr.metrics.ui.charts.DiffHistogramDialog.java

private JFreeChart createChart(IntervalXYDataset dataset, boolean isIntegral) {
    final String title = getTitle();
    final NumberAxis xAxis = new NumberAxis();
    if (metricType.equals(MetricType.Ratio) || metricType.equals(MetricType.RecursiveRatio)) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }/* www . j a va2  s . c  o  m*/
    if (isIntegral) {
        xAxis.setTickUnit(new NumberTickUnit(1.0));
    }

    final XYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator();

    final XYItemRenderer renderer = new XYBarRenderer();
    renderer.setToolTipGenerator(tooltipGenerator);
    renderer.setURLGenerator(null);

    final ValueAxis yAxis = new NumberAxis();
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:edu.ucla.stat.SOCR.chart.demo.DifferenceChartDemo1.java

/**
 * Creates a chart.//from  ww  w  .  j a va 2  s  .  c o m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, rangeLabel, dataset,
            !legendPanelOn, // legend
            true, // tool tips
            false // URLs
    );
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDifferenceRenderer(Color.green, Color.red, false));
    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.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    ValueAxis domainAxis = new DateAxis("Time");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    //setXSummary(dataset) X is time;          
    return chart;

}

From source file:IHM.NewClass.java

/**
 *
 * @param title//from  w  ww.j a v a2 s .c o  m
 */
public NewClass(String title /*,*JInternalFrame jp*/) {
    super(title);
    // jp = new JInternalFrame("courbes");

    JFreeChart chart = createChart(createDataset());
    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new Dimension(500, 300));
    setContentPane(panel);
    //  jp.add(panel, BorderLayout.EAST);
    //  jp.setVisible(true);
    panel.setVisible(true);
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);
    plot.setOutlinePaint(Color.BLUE);
    plot.setOutlineStroke(new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLACK);

}