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.activequant.util.charting.EquityChart.java

/**
 * sets the equity chart on this object, but does not render it. Call renderToXYZ to actually render it. 
 * @param balanceBook/*from w w  w.  ja  v a2 s .com*/
 */
public void createEquityChart(BalanceBook balanceBook) {

    final TimeSeries ts = new TimeSeries("Equity curve", Millisecond.class);
    double value = 0.0;
    for (BalanceEntry be : balanceBook.getBalanceEntries()) {
        value += be.getValue();
        ts.addOrUpdate(new Millisecond(be.getTimeStamp().getDate()), value);
    }
    final TimeSeriesCollection dataset = new TimeSeriesCollection(ts);

    final XYPlot plot1 = chart.getXYPlot();
    plot1.setDataset(0, dataset);

}

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

/**
 * Creates a sample chart.//from www  . j av  a 2  s.  co m
 * 
 * @param dataset  a dataset.
 * 
 * @return a sample chart.
 */
private JFreeChart createChart(final DefaultHighLowDataset dataset) {

    final JFreeChart chart = ChartFactory.createHighLowChart("OHLC Demo 2", "Time", "Value", dataset, true);

    final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    final XYDataset dataset2 = MovingAverage.createMovingAverage(dataset, "-MAVG", 3 * 24 * 60 * 60 * 1000L,
            0L);
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, new StandardXYItemRenderer());

    return chart;

}

From source file:subterranean.crimson.server.graphics.graphs.LineChart.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false);

    XYPlot plot = result.getXYPlot();
    plot.setDataset(1, new TimeSeriesCollection(s2));

    plot.setBackgroundPaint(new Color(0x000000));
    plot.setDomainGridlinesVisible(false);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);//from www .j av a  2 s  .c  o  m

    xaxis.setFixedAutoRange(160000.0); // 160 seconds
    xaxis.setVerticalTickLabels(false);

    ValueAxis yaxis = plot.getRangeAxis();

    yaxis.setAutoRange(true);
    yaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return result;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createPriceDataset();
    String s = "Eurodollar Futures Contract (MAR03)";
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(s, "Date", "Price", xydataset, true, true,
            false);/*from   ww  w. ja  v  a2  s . co  m*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setLowerMargin(0.40000000000000002D);
    DecimalFormat decimalformat = new DecimalFormat("00.00");
    numberaxis.setNumberFormatOverride(decimalformat);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    NumberAxis numberaxis1 = new NumberAxis("Volume");
    numberaxis1.setUpperMargin(1.0D);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createVolumeDataset());
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D);
    xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00")));
    xyplot.setRenderer(1, xybarrenderer);
    return jfreechart;
}

From source file:net.sourceforge.processdash.ui.web.reports.XYChart.java

private void addTrendLine(JFreeChart chart, XYDataset dataset) {
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, dataset);
    plot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.LINES));
}

From source file:com.romraider.logger.ecu.ui.tab.LoggerChartPanel.java

private void addTrendLine(JFreeChart chart, int index, XYTrendline trendline, Color color) {
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(index, trendline);
    plot.setRenderer(index, buildTrendLineRenderer(color));
}

From source file:com.romraider.logger.ecu.ui.tab.LoggerChartPanel.java

private void addSeries(JFreeChart chart, int index, XYSeries series, int size, Color color) {
    XYDataset dataset = new XYSeriesCollection(series);
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(index, dataset);
    plot.setRenderer(index, buildScatterRenderer(size, color));
}

From source file:de.kletterfreak98.xmass.ui.BMIChart.java

public BMIChart(String title, TimeSeries values) {
    super(title);
    setIconImage(//from  w w  w.jav a 2  s  . com
            new ImageIcon(getClass().getClassLoader().getResource("de/kletterfreak98/xmass/resources/fav.png"))
                    .getImage());

    // create a title...
    final String chartTitle = strings.getString("bmicourse");
    final XYDataset dataset = new TimeSeriesCollection(values);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, strings.getString("date"),
            strings.getString("bmi"), dataset, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, new TimeSeriesCollection(values));
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setShapesFilled(true);
    }

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

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    SimpleDateFormat sdf;
    if (Main.settings.getLang().equals(Locale.GERMANY)) {
        sdf = new SimpleDateFormat("dd.MM.yyyy");
    } else {
        sdf = new SimpleDateFormat("MM/dd/yyyy");
    }
    axis.setDateFormatOverride(sdf);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    JPanel panel = new JPanel();
    JButton close = new JButton(strings.getString("close"));
    close.setPreferredSize(new Dimension(close.getWidth(), 30));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel, BorderLayout.CENTER);
    panel.add(close, BorderLayout.SOUTH);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(panel);
    setUndecorated(true);
}

From source file:de.kletterfreak98.xmass.ui.WeightChart.java

public WeightChart(String title, TimeSeries values) {
    super(title);

    setIconImage(//from   w  w  w  . j av  a  2 s . c  o m
            new ImageIcon(getClass().getClassLoader().getResource("de/kletterfreak98/xmass/resources/fav.png"))
                    .getImage());

    final String chartTitle = strings.getString("weightcourse");
    final XYDataset dataset = new TimeSeriesCollection(values);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, strings.getString("date"),
            strings.getString("weightinkg"), dataset, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, new TimeSeriesCollection(values));
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setShapesFilled(true);
    }

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

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    SimpleDateFormat sdf;
    if (Main.settings.getLang().equals(Locale.GERMANY)) {
        sdf = new SimpleDateFormat("dd.MM.yyyy");
        axis.setDateFormatOverride(sdf);
    } else {
        sdf = new SimpleDateFormat("MM/dd/yyyy");
        axis.setDateFormatOverride(sdf);
    }

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    JPanel panel = new JPanel();
    JButton close = new JButton(strings.getString("close"));
    close.setPreferredSize(new Dimension(close.getWidth(), 30));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel, BorderLayout.CENTER);
    panel.add(close, BorderLayout.SOUTH);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(panel);
    setUndecorated(true);
}

From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java

public void updatePersonDataset(HistogramChartDataset data) {
    //set histogram data
    CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) chart.getPlot();
    List plots = cplot.getSubplots();
    XYPlot p = (XYPlot) plots.get(0);
    p.setDataset(0, data);
}