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:ec.ui.view.MarginView.java

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

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

    plot.setDataset(MAIN_INDEX, TsXYDatasets.from("series", data.series));
    plot.setDataset(DIFFERENCE_INDEX,//from  ww  w  . j  a v  a 2  s .  co m
            TsXYDatasets.builder().add("lower", data.lower).add("upper", data.upper).build());

    onPrecisionMarkersVisible();
    onDataFormatChange();

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

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

protected void completarPlot(final XYPlot plot, final JanelaGraficos janela) {
    IntervalXYDataset dataVolume = criarVolumeDataset(janela);
    XYBarRenderer volumeRenderer = new XYBarRenderer();
    volumeRenderer.setSeriesPaint(0, Controle.getConfiguracoesUsuario().getCorVolume());
    volumeRenderer.setDrawBarOutline(false);
    volumeRenderer.setMargin((double) Controle.getConfiguracoesUsuario().getEspacColunasVolume() / 10);
    volumeRenderer.setToolTipGenerator(new CandlesToolTipGenerator(janela));
    plot.setDataset(indices.size(), dataVolume);
    plot.setRenderer(indices.size(), volumeRenderer);
}

From source file:org.operamasks.faces.render.graph.CompositeChartRenderer.java

private JFreeChart createXYCompositeChart(List<JFreeChart> subcharts, UIChart comp) {
    XYPlot compositePlot = new XYPlot();
    compositePlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    compositePlot.setOrientation(getChartOrientation(comp));

    for (int i = 0; i < subcharts.size(); i++) {
        XYPlot subplot = (XYPlot) subcharts.get(i).getPlot();
        compositePlot.setDataset(i, subplot.getDataset());
        compositePlot.setRenderer(i, subplot.getRenderer());

        if (i == 0) {
            compositePlot.setDomainAxis(0, subplot.getDomainAxis());
            compositePlot.setRangeAxis(0, subplot.getRangeAxis());
        } else {// www  .j a  v  a 2s  .c om
            int yAxisMap = getRangeAxisMap(comp, i);
            ValueAxis yAxis = null;
            if (yAxisMap == -1) {
                yAxisMap = 0; // map to axis zero by default
            } else if (yAxisMap == i) {
                yAxis = subplot.getRangeAxis(); // add subplot axis to composite plot
            }
            compositePlot.setRangeAxis(i, yAxis);
            compositePlot.mapDatasetToRangeAxis(i, yAxisMap);
        }
    }

    return new JFreeChart(null, null, compositePlot, false);
}

From source file:net.sf.clichart.chart.AbstractChartBuilder.java

private void setAxisRenderer(XYPlot plot, int axisIndex, boolean isBarChart, boolean hasDataPoints,
        int lineWeight) {
    XYItemRenderer renderer;//from  w ww  .  jav  a 2s . c o  m
    if (isBarChart) {
        renderer = new ClusteredXYBarRenderer();
        XYDataset axisDataset = plot.getDataset(axisIndex);
        plot.setDataset(axisIndex, new XYBarDataset(axisDataset, calculateBarWidth(axisDataset, lineWeight)));

    } else {
        renderer = new XYLineAndShapeRenderer(true, hasDataPoints);

        if (lineWeight >= 0 && lineWeight <= 5) {
            for (int seriesIndex = 0; seriesIndex < plot.getDataset(axisIndex)
                    .getSeriesCount(); seriesIndex++) {
                renderer.setSeriesStroke(seriesIndex, new BasicStroke((float) lineWeight));
            }
        }
    }
    renderer.setBaseToolTipGenerator(getToolTipGenerator());
    plot.setRenderer(axisIndex, renderer);
}

From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java

@Override
public XYPlot getPlot(List<NumberPhenomenon> dataList) {

    XYPlot plot = new XYPlot();

    plot.setDomainAxis(getDomainAxis(dataList));

    Map<String, Integer> axes = createRangeAxes(dataList, plot);

    for (int i = 0; i < dataList.size(); i++) {
        NumberPhenomenon phenomenon = dataList.get(i);
        //addTimeSeries(plot, phenomenon, i, colors[i % colors.length]);

        plot.setDataset(i, getTimeSeries(phenomenon));
        plot.setRenderer(i, new XYSplineRenderer());
        plot.getRenderer(i).setSeriesPaint(0, colors[i % colors.length]);

        plot.mapDatasetToRangeAxis(i, axes.get(phenomenon.getPhenomenonUnit()));
    }//from  w  w  w .  j  a  v  a 2  s  . co m

    return plot;
}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*w  w w  .  ja  v a 2s .c  o  m*/
 */
public DynamicDataDemo2(final String title) {

    super(title);
    this.series1 = new TimeSeries("Random 1", Millisecond.class);
    this.series2 = new TimeSeries("Random 2", Millisecond.class);
    final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value",
            dataset1, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    plot.setDataset(1, dataset2);
    final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(1, new DefaultXYItemRenderer());
    plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add To Series 1");
    button1.setActionCommand("ADD_DATA_1");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Add To Series 2");
    button2.setActionCommand("ADD_DATA_2");
    button2.addActionListener(this);

    final JButton button3 = new JButton("Add To Both");
    button3.setActionCommand("ADD_BOTH");
    button3.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

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);/*from  w  w w.  java2 s .  c  o  m*/
    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:playground.dgrether.linkanalysis.DgCountPerIterationGraph.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Iteration");
    xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2);
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Trips");
    //      yAxis.setRange(-0.05, 0.3);
    //      xAxis.setVisible(false);
    //      xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);//from  www.java  2 s .c  o  m
    plot.setRangeAxis(yAxis);

    plot.setDataset(0, this.dataset);

    DgColorScheme colorScheme = new DgColorScheme();
    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    for (int i = 0; i < this.dataset.getSeriesCount(); i++) {
        renderer2.setSeriesItemLabelsVisible(i, true);
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    //      renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    //      renderer2.setSeriesStroke(1, new BasicStroke(2.0f));
    //      renderer2.setSeriesOutlineStroke(1, new BasicStroke(3.0f));
    //      renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a"));

    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    //      chart.removeLegend();
    return chart;
}

From source file:umontreal.iro.lecuyer.charts.XYLineChart.java

/**
 * Displays bar chart on the screen using Swing.
 *    This method creates an application containing a bar chart panel displaying
 *    the chart.  The created frame is positioned on-screen, and displayed before
 *    it is returned. The <TT>width</TT> and the <TT>height</TT>
 *    of the chart are measured in pixels.
 * /*from w ww .j  a  va 2 s .co m*/
 * @param width frame width in pixels.
 * 
 *    @param height frame height in pixels.
 * 
 *    @return frame containing the bar chart.;
 * 
 */
public JFrame viewBar(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("XYLineChart from SSJ: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("XYLineChart from SSJ");

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

    //Create the bar
    plot.setDataset(0, dataset.getSeriesCollection());
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.ORANGE);
    renderer.setSeriesShape(0, new Line2D.Double(0, 0, 0, 1000));
    plot.setRenderer(0, renderer);

    //Create the points
    plot.setDataset(1, dataset.getSeriesCollection());
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
    renderer2.setSeriesPaint(0, Color.ORANGE);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
    plot.setRenderer(1, renderer2);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    myFrame.setVisible(true);
    return myFrame;
}

From source file:daylightchart.daylightchart.chart.DaylightChart.java

/**
 * Creates bands for the sunrise and sunset times for the whole year.
 *///from  w  w w .  ja  va  2  s  .c  o m
private void createBandsInPlot(final XYPlot plot) {
    final List<DaylightBand> bands = riseSetData.getBands();
    for (final DaylightBand band : bands) {
        final DaylightChartBand chartBand = new DaylightChartBand(band);
        LOGGER.log(Level.FINE, band.toString());
        final int currentDatasetNumber = plot.getDatasetCount();
        plot.setDataset(currentDatasetNumber, chartBand.getTimeSeriesCollection());
        plot.setRenderer(currentDatasetNumber, chartBand.getRenderer());
    }
}