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:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo1.java

protected JFreeChart createLegend(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, //"Time of Day", 
            rangeLabel, //"Value",
            dataset, !legendPanelOn, true, false);

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

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(Color.black);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;

}

From source file:com.googlecode.logVisualizer.chart.MPGainedSpentPerTurnXYBarChart.java

/**
 * Method overridden to make the MP spent bar colour use a bit of alpha,
 * otherwise MP gains below MP spent wouldn't be viewable.
 *///from   w w  w .j a va2s . c o m
@Override
protected ChartPanel createChartPanel() {
    final ChartPanel panel = super.createChartPanel();
    final XYPlot plot = (XYPlot) panel.getChart().getPlot();
    final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    final XYDataset dataset = plot.getDataset();

    for (int i = 0; i < dataset.getSeriesCount(); i++)
        if (dataset.getSeriesKey(i).equals("MP spent"))
            renderer.setSeriesPaint(i, new Color(255, 80, 80, 200));
        else if (dataset.getSeriesKey(i).equals("MP gained"))
            renderer.setSeriesPaint(i, new Color(100, 100, 255));

    return panel;
}

From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java

private void updateModel() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYPlot plot = ((XYPlot) getChart().getPlot());
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    // the x=0 line
    XYSeries line = new XYSeries("");
    line.add(1.0, 0.0);// w w  w. j av  a  2s .  c o  m
    line.add(project.getPeriods(), 0.0);
    dataset.addSeries(line);

    // adds the line plot for each mmf
    int[][] saNpvValues = project.getSaNpvTable();
    for (int mmfI = 0; mmfI < saNpvValues.length; mmfI++) {
        Mmf mmf = project.get(mmfI);
        XYSeries values = new XYSeries(mmf.getId() + ": " + mmf.getName());

        for (int period = 1; period <= saNpvValues[mmfI].length; period++) {
            values.add(period, saNpvValues[mmfI][period - 1]);
        }

        dataset.addSeries(values);
        renderer.setSeriesShapesVisible(mmfI + 1, false);
        renderer.setSeriesStroke(mmfI + 1, SERIES_STROKE);
        renderer.setSeriesPaint(mmfI + 1, CHART_COLOR[mmfI % CHART_COLOR.length]);
    }

    plot.setDataset(dataset);
}

From source file:org.mc.okapi.Plot.java

public Plot(double[] X, double[] Y, String xLab, String yLab, String seriesName, String applicationTitle,
        String chartTitle) {//from  w w  w  .j  a  v a 2  s  .c om
    super(applicationTitle);

    XYSeries series = new XYSeries(seriesName);

    for (int i = 0; i < X.length; i++) {
        series.add(X[i], Y[i]);
    }
    // create a dataset...
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    // based on the dataset we create the chart        
    JFreeChart chart = ChartFactory.createScatterPlot(chartTitle, xLab, yLab, dataset, PlotOrientation.VERTICAL,
            true, rootPaneCheckingEnabled, rootPaneCheckingEnabled);
    Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesShape(0, cross);
    renderer.setSeriesPaint(0, Color.red);

    // we put the chart into a panel
    ChartPanel chartPanel = new ChartPanel(chart);
    setIconImage(Toolkit.getDefaultToolkit().getImage("images/ico/extra/science_32.png"));

    // default size
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    // add it to our application
    setContentPane(chartPanel);

}

From source file:au.edu.jcu.usb.USBPlotFrame.java

/**
 * Constructs the ChartPanel from the provided XYSeriesCollection
 *
 * @param xySeriesCollection//from  w  w  w.  j  a va2s.  c  o m
 * @return The constructed ChartPanel containing the XY scatter plot
 */
private ChartPanel constructChart(XYSeriesCollection xySeriesCollection) {
    // Construct the scatter plot from the provided xySeriesCollection
    JFreeChart chart = ChartFactory.createScatterPlot("Title", "X Axis", "Y Axis", xySeriesCollection);

    // Get the XY Plot from the scatter chart
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    // Create the renderer
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);

    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();

    domain.setVerticalTickLabels(true);

    ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

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

protected JFreeChart createLegend(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, rangeLabel, dataset,
            !legendPanelOn, // legend
            true, // tool tips
            false // URLs
    );/*from w  ww .j  ava2  s.  c  o m*/

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

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;

}

From source file:Demo.HistGraph.java

private JFreeChart CreateChart(String para) {
    // read .dat file
    double[] value = Utils.GetParaTab(para);

    // generate chart
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.FREQUENCY);
    dataset.addSeries(para, value, 20);//from   ww  w  . j  av a  2  s . co  m

    String plotTitle = para;
    String xaxis = "value";
    String yaxis = "frequecy";
    PlotOrientation orientation = PlotOrientation.VERTICAL;

    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, dataset, orientation, show,
            toolTips, urls);

    final XYPlot xyPlot = chart.getXYPlot();
    final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.BLUE);

    return chart;
}

From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) {
        plot.getRenderer().setSeriesPaint(i, themeSupport.getLineColor(i));
    }/*  www .j a  va  2 s .  c o  m*/
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());
}

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

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, true, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, 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();

    StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    renderer.setBaseToolTipGenerator(generator);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    axis.setLowerMargin(0.01);/*w ww .  j  a  v a2  s  .  c  o  m*/
    axis.setUpperMargin(0.01);
    //      setXSummary(dataset);  X  is time
    return chart;
}

From source file:org.jfree.fx.demo.FXGraphics2DDemo1.java

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

    JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", // title
            null, // x-axis label
            "US cents/lb", // y-axis label
            dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf",
            new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return chart;

}