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

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

Introduction

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

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

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

Usage

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

/**
 * Creates a combined chart./*from  ww  w .  j  ava2 s. c  o m*/
 *
 * @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:uk.co.moonsit.sockets.DualAxisDemo2.java

/**
 * A demonstration application showing how to create a time series chart with dual axes.
 *
 * @param title  the frame title./*from   w w w  .  jav  a  2 s .c o m*/
 */
public DualAxisDemo2(final String title) {

    super(title);

    // create a title...
    final String chartTitle = "Dual Axis Demo 2";
    final XYDataset dataset = createDataset1();

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset,
            true, true, false);

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

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis axis2 = new NumberAxis("Secondary");
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, createDataset2());
    plot.mapDatasetToRangeAxis(1, 1);
    /*final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
    final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
    //rr.setPlotShapes(true);
    rr.setShapesFilled(true);
    }*/

    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.black);
    //renderer2.setPlotShapes(true);
    //renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

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

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.ow2.clif.jenkins.chart.MovingStatChart.java

private void attachThroughputDatasetToDedicatedAxis(XYSeriesCollection throughputDataset, XYPlot plot) {
    NumberAxis throughputAxis = new NumberAxis(Messages.MovingChart_Throughput());
    plot.setRangeAxis(1, throughputAxis);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, throughputDataset);
    plot.mapDatasetToDomainAxis(1, 0);/*from  www . j  a v  a2s.co  m*/
    plot.mapDatasetToRangeAxis(1, 1);
}

From source file:com.trivadis.loganalysis.ui.ChartPanel.java

private void add(final Serie serie) {
    if (!isDisposed()) {
        serie.setIndex(seriesSequence.get());
        final XYSeriesCollection dataset = new XYSeriesCollection(datasetProvider.getDataset(jvm, serie));
        final int index = serie.getIndex();
        final XYPlot plot = (XYPlot) jfreeChart.getPlot();
        final Color color = getColor(index);
        removeDataset(index, plot);/*from w  w w.  j  av  a  2  s  .  c om*/
        plot.setDataset(index, dataset);
        plot.setRangeAxis(index, axis(color, serie.getYaxis().getValueProvider().getUnit()));
        plot.setDomainAxis(index, axis(color, serie.getXaxis().getValueProvider().getUnit()));
        plot.mapDatasetToDomainAxis(index, index);
        plot.mapDatasetToRangeAxis(index, index);
        plot.setRenderer(index, getRenderer(color, serie.isDotted()));
        seriesSequence.incrementAndGet();
    }
}

From source file:com.trivadis.loganalysis.ui.ChartPanel.java

/**
 * This method first removes the change listener, otherwise the change
 * listener will act on a already disposed widget.
 * /*from  w w  w.jav  a  2 s .  c o m*/
 * @param index
 * @param plot
 */
private void removeDataset(final int index, final XYPlot plot) {
    final XYDataset existing = plot.getDataset(index);
    if (existing != null)
        existing.removeChangeListener(plot);
    plot.setDataset(index, null);
}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

public ChartPanel criaGrafico() {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("MAP ENTRE AS QUERYS", // chart title  
            "QUERY", // x axis label  
            "MAP", // y axis label  
            createDataset1(), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );//  w  w w  . j  av a  2s. c o m

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

    // get a reference to the plot for further customisation...  
    XYPlot plot = (XYPlot) graf.getPlot();
    plot.setDataset(1, createDataset2());
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(false);

    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(1, renderer2);

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

    ChartPanel myChartPanel = new ChartPanel(graf, true);
    return myChartPanel;
}

From source file:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java

/**
 * Creates a chart.//from   www .  j  a  v a  2  s  .  c o m
 *
 * @param dataset1  a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset, long lastentry) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "time", // x-axis label
            "temperature", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

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

    NumberAxis axis1 = new NumberAxis(getAxisName());
    axis1.setAutoRangeIncludesZero(isIncludeZero());
    plot.setRangeAxis(0, axis1);

    plot.setDataset(0, dataset);
    plot.mapDatasetToRangeAxis(1, 0);

    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);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    r1.setSeriesPaint(0, Color.BLUE);
    r1.setSeriesPaint(1, Color.RED);
    r1.setSeriesPaint(2, Color.GREEN);

    //plot.setDomainAxis(new NumberAxis("time"));
    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = getRangeBegin(lastentry);
    long end = getRangeEnd(lastentry);

    plot.getDomainAxis().setRange(begin, end);

    return chart;
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createTradeChart() {
    JFreeChart chart = ChartFactory.createXYLineChart("Trading and Population over Time", "Time", "Level",
            model.agents_series_coll, PlotOrientation.VERTICAL, true, true, false);
    model.trade_chart = chart;/*from   w  ww  . ja v a 2  s.  com*/
    NumberAxis rangeAxis1 = new NumberAxis("Time");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins");
    XYPlot plot = chart.getXYPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.BLUE);
    plot.setDataset(1, model.trade_coll);
    XYItemRenderer rend2 = new StandardXYItemRenderer();
    //if (rend2 != null)
    rend2.setSeriesPaint(1, Color.BLACK);
    plot.setRenderer(1, rend2);
    return chart;
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createEvolution() {
    JFreeChart chart = ChartFactory.createXYLineChart("Evolution of Mean Agent Vision and Metabolism", "Time",
            "Level", model.evolution_vision_coll, PlotOrientation.VERTICAL, true, true, false);
    model.evolution_chart = chart;//from w w w  . j  a  v  a2  s  . c o m
    NumberAxis rangeAxis1 = new NumberAxis("Time");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins");
    XYPlot plot = chart.getXYPlot();
    ValueAxis xAxis = plot.getDomainAxis();

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    plot.setDataset(1, model.evolution_metabolism_coll);
    renderer.setSeriesPaint(1, Color.BLUE);
    return chart;
}

From source file:be.nbb.demetra.dfm.output.FactorChart.java

private void onDataChange() {
    chartPanel.getChart().setNotify(false);

    XYPlot plot = chartPanel.getChart().getXYPlot();

    plot.setDataset(FACTOR_INDEX, TsXYDatasets.from("factor", data.factor));
    plot.setDataset(FILTERED_INDEX, TsXYDatasets.from("filtered", data.filtered));
    plot.setDataset(DIFFERENCE_INDEX,/*from ww  w .j a va2s .c o  m*/
            TsXYDatasets.builder().add("lower", data.lower).add("upper", data.upper).build());

    onDataFormatChange();

    chartPanel.getChart().setNotify(true);
}