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(int index, XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the dataset with the specified index and sends a change event to all registered listeners.

Usage

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

/**
 * Creates a combined chart./*from  w  w w  .j a  v a2 s .  c om*/
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // add secondary axis
    subplot1.setDataset(1, createDataset2());
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    subplot1.setRangeAxis(1, axis2);
    subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    subplot1.setRenderer(1, new StandardXYItemRenderer());
    subplot1.mapDatasetToRangeAxis(1, 1);

    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

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 w  w  w . j  ava  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:playground.dgrether.analysis.charts.DgMixedModeSwitcherOnlyDeltaScoreIncomeModeChoiceChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);/*  w w w. j  a va 2  s.c om*/
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true);
    renderer1.setSeriesPaint(0, colorScheme.COLOR3B);
    renderer1.setSeriesPaint(1, colorScheme.COLOR4B);
    plot.setDataset(0, this.inomeModeChoiceDs);
    plot.setRenderer(0, renderer1);

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(1, this.avgDeltaScoreIncomeDs);
    for (int i = 2; i <= 3; i++) {
        renderer2.setSeriesStroke(i - 2, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i - 2, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i - 2, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(1, renderer2);
    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:ucar.unidata.idv.control.chart.VerticalProfileChart.java

/**
 * Initialize the plot/*from www .jav  a  2  s.c  o m*/
 *
 * @param plot the plot to initialize
 */
protected void initPlot(Plot plot) {
    XYPlot xyPlot = (XYPlot) plot;
    xyPlot.setOrientation(PlotOrientation.HORIZONTAL);

    int count = xyPlot.getDatasetCount();
    for (int i = 0; i < count; i++) {
        xyPlot.setDataset(i, null);
        xyPlot.setRenderer(i, null);
    }
    xyPlot.clearRangeAxes();
    XYSeriesCollection dummyDataset = new XYSeriesCollection();
    //ValueAxis          rangeAxis    = new FixedWidthNumberAxis();
    ValueAxis rangeAxis = new NumberAxis();
    xyPlot.setRangeAxis(0, rangeAxis, false);
    xyPlot.setDataset(0, dummyDataset);
    xyPlot.mapDatasetToRangeAxis(0, 0);
    xyPlot.setRenderer(0, new XYLineAndShapeRenderer());
}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java

public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1,
        String protocol2) {/*ww w  .j  a v  a  2s  .  c  o m*/
    // ?
    XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1);
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();

    XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer();
    // ??1?1

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D);
    // ???

    // ??
    xylineandshaperenderer1.setSeriesLinesVisible(0, true);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F));

    // ?
    XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2);
    /*      XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10,
    Double.parseDouble(abnor.getElementAt(10).getData()));
          xyplot.addAnnotation(localXYTextAnnotation);*/
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    int datasetcount = xyplot.getDatasetCount();
    xyplot.setDataset(datasetcount, xydataset2);
    xyplot.setRenderer(datasetcount, xylineandshaperenderer2);
    /*      System.out.println("DatasetCount="+xyplot.getDatasetCount());
                  
          for(int c=0;c<xyplot.getDatasetCount();c++){
             System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount());
             System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0));
          }*/

    /*   // ??? 
       xylineandshaperenderer2.setBaseShapesVisible(false);
       // ??
       xylineandshaperenderer2.setSeriesLinesVisible(0, true);
       xylineandshaperenderer2.setSeriesShape(0, double1);
       // 
       xylineandshaperenderer2.setSeriesPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesFillPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
            
       xylineandshaperenderer2.setUseFillPaint(true);
       xylineandshaperenderer2
    .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
       xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
               
    */
    xylineandshaperenderer2.setSeriesLinesVisible(0, true);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
    xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
    jfreechart.getLegend().setVisible(true);
    return jfreechart;

}

From source file:grafix.graficos.eixos.EixoCandles.java

protected void completarPlot(final XYPlot plot, final JanelaGraficos janela) {
    OHLCDataset dataCandles = criarOHLCDataset(janela);
    CandlestickRenderer candRenderer = new CandlestickRenderer();
    candRenderer.setUpPaint(Controle.getConfiguracoesUsuario().getCorCandlesAlta());
    candRenderer.setDownPaint(Controle.getConfiguracoesUsuario().getCorCandlesBaixa());
    candRenderer.setSeriesPaint(0, Color.black);
    candRenderer.setStroke(new BasicStroke(.75f));
    candRenderer.setToolTipGenerator(new CandlesToolTipGenerator(janela));
    plot.setDataset(indices.size(), dataCandles);
    plot.setRenderer(indices.size(), candRenderer);
    incluirMarcaIntraday(plot, janela);/* w  ww  .j  a  va 2  s .c  o  m*/
}

From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java

/**
 * Creates the Chart of the Degree Distribution according to the calculated
 * distribution/*from  w  w w  .  j ava  2  s .c  o  m*/
 * 
 * @param degreeDistribution
 * @return a {@link JFreeChart} containing the distribution of degrees in
 *         the graph
 * @throws IOException
 */
public JFreeChart createDegreeDistributionChart(Map<Integer, Integer> degreeDistribution) throws IOException {
    XYSeries dSeries = new XYSeries("number of occurences");
    for (Iterator it = degreeDistribution.entrySet().iterator(); it.hasNext();) {
        Map.Entry d = (Map.Entry) it.next();
        Number x = (Number) d.getKey();
        Number y = (Number) d.getValue();
        dSeries.add(x, y);
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);
    dataset.setAutoWidth(true);

    JFreeChart chart = ChartFactory.createHistogram("Degree Distribution", "Degree centrality value",
            "number of occurences", dataset, PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer0 = new XYBarRenderer();
    Font font = new Font("Font", 0, 14);
    renderer0.setMargin(0.2);
    renderer0.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer0.setBaseItemLabelsVisible(true);
    renderer0.setBaseItemLabelFont(font);
    plot.setDataset(0, dataset);
    plot.setRenderer(0, renderer0);
    plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.BLUE);
    return chart;
}

From source file:org.graphstream.algorithm.measure.ChartMinMaxAverageSeriesMeasure.java

public JFreeChart createChart(PlotParameters params) throws PlotException {
    XYSeriesCollection minMax = new XYSeriesCollection();
    XYSeriesCollection avgCol = new XYSeriesCollection();
    XYPlot plot;
    XYBarRenderer r = new XYBarRenderer();
    r.setBarPainter(new StandardXYBarPainter());
    r.setMargin(0.35);/*from  w w w.  j ava2s  .  c om*/

    minMax.addSeries(min);
    avgCol.addSeries(series);
    minMax.addSeries(max);

    JFreeChart chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel,
            avgCol, params.orientation, params.showLegend, true, false);

    plot = ((XYPlot) chart.getPlot());
    plot.setDataset(1, minMax);
    plot.setRenderer(1, r);

    if (separateMinMaxAxis) {
        NumberAxis minMaxAxis = new NumberAxis("min/max");

        plot.setRangeAxis(1, minMaxAxis);
        plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    return chart;
}

From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java

/**
 * Creates the Chart of the Clustering Distribution according to the
 * calculated distribution/*w  w  w  . ja va  2 s  .  c o  m*/
 * 
 * @param clusterDistribution
 * @return a {@link JFreeChart} containing the distribution of local cluster
 *         coefficients in the graph
 * @throws IOException
 */
public JFreeChart createClusterDistributionChart(Map<Double, Integer> clusterDistribution) throws IOException {
    XYSeries dSeries = new XYSeries("number of occurences");
    for (Iterator it = clusterDistribution.entrySet().iterator(); it.hasNext();) {
        Map.Entry d = (Map.Entry) it.next();
        Number x = (Number) d.getKey();
        Number y = (Number) d.getValue();
        dSeries.add(x, y);
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);
    dataset.setAutoWidth(true);

    JFreeChart chart = ChartFactory.createHistogram("Local Cluster Coefficient Distribution",
            "Local Cluster Coefficient value", "number of occurences", dataset, PlotOrientation.VERTICAL, true,
            true, true);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer0 = new XYBarRenderer();
    Font font = new Font("Font", 0, 14);
    renderer0.setMargin(0.2);
    renderer0.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer0.setBaseItemLabelsVisible(true);
    renderer0.setBaseItemLabelFont(font);
    plot.setDataset(0, dataset);
    plot.setRenderer(0, renderer0);

    plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.BLUE);

    return chart;
}

From source file:com.bdb.weather.display.freeplot.FreePlotSeriesCollection.java

/**
 * Constructor./* w  ww. ja  va  2s  .c o  m*/
 * 
 * @param groupName The name of this group
 * @param units The units of this collection, used to setup the Range Axis
 * @param datasetIndex The dataset index from a JFreePlot perspective
 * @param domainAxisIndex The index of the domain axis, from a JFreeChart perspective
 * @param plot The plot to which the dataset and axis will be added
 * @param stroke The Stroke used to draw the series of this collection
 * @param factory The factory used to create the series
 */
FreePlotSeriesCollection(String groupName, Unit units, int datasetIndex, int domainAxisIndex, XYPlot plot,
        Stroke stroke, SeriesFactory<T> factory) {
    this.groupName = groupName;
    this.dataset = new TimeSeriesCollection();
    this.datasetIndex = datasetIndex;
    this.factory = factory;
    this.plot = plot;
    renderer = new DefaultXYItemRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    renderer.setDrawSeriesLineAsPath(true);
    plot.setDataset(datasetIndex, dataset);
    plot.setRenderer(datasetIndex, renderer);
    series = factory.createSeriesGroup(groupName, stroke);
    plot.mapDatasetToDomainAxis(datasetIndex, domainAxisIndex);
}