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:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java

private synchronized void addToCombined(LoggerData loggerData) {
    if (combinedChartPanel == null) {
        combinedChartPanel = new ChartPanel(createXYLineChart(loggerData, null, true), false, true, true, true,
                true);/*from   ww w. j  a  va 2s. c  o  m*/
        LegendTitle legendTitle = new LegendTitle(combinedChartPanel.getChart().getXYPlot());
        legendTitle.setItemPaint(WHITE);
        combinedChartPanel.getChart().addLegend(legendTitle);
        combinedChartPanel.setMinimumSize(new Dimension(500, 400));
        combinedChartPanel.setPreferredSize(new Dimension(500, 400));
        graphPanel.add(combinedChartPanel);
    }
    XYPlot plot = combinedChartPanel.getChart().getXYPlot();
    plot.setDataset(counter, new XYSeriesCollection(seriesMap.get(loggerData)));
    plot.setRenderer(counter, new StandardXYItemRenderer());
    datasetIndexes.put(loggerData, counter++);
}

From source file:sentimentanalyzer.ChartController.java

public void addLineOfDataTo_XYSeriesLineChart(XYSeriesCollection dataset, int row, XYPlot plot) {
    plot.setDataset(row, dataset);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesPaint(row, this.getRandomColor());
    plot.setRenderer(row, renderer);//from ww w .j a va  2  s . c  o m

    this.wordIndexesOnGraph.add(row);
}

From source file:in.BBAT.presenter.DualAxisDemo2.java

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

    super(title);

    // create a title...
    final String chartTitle = "Memory & CPU usage";
    final XYDataset dataset = createDataset1();

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Time", "Memory usage (kB)",
            dataset, true, true, false);

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

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis axis2 = new NumberAxis("CPU usage (%)");
    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("hh:mm:ss"));

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

}

From source file:ec.nbdemetra.benchmarking.calendarization.CalendarizationChartView.java

/**
 * Sets data to display on the graph. This method is used to add smoothed
 * and given periods data to the graph.//  w  ww . j a v  a2  s .  co m
 *
 * @param days All the given periods
 * @param smooth Serie of calculated smoothed daily data
 * @param smoothDevs 2 smoothed data series : 1) smoothed data lowered by
 * the standard deviation and 2) smoothed data increased by the standard
 * deviation
 */
public void setData(TimeSeriesCollection days, TimeSeries smooth, TimeSeriesCollection smoothDevs) {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    chartPanel.getChart().setTitle(new TextTitle("Smoothed Data", new Font("SansSerif", Font.PLAIN, 12)));

    plot.setDataset(DAILY_INDEX, days);
    plot.setDataset(SMOOTH_INDEX, new TimeSeriesCollection(smooth));
    plot.setDataset(DIFF_INDEX, smoothDevs);

    onDataFormatChange();
    onColorSchemeChange();
}

From source file:ec.nbdemetra.benchmarking.calendarization.CalendarizationChartView.java

/**
 * Sets data to display on the graph. This method is used to add aggregates
 * data to the graph./* www.j  a va2 s  .c  o  m*/
 *
 * @param serie Aggregrated serie of data
 * @param lower Aggregated serie of data lowered by the standard deviation
 * @param upper Aggregated serie of data increased by the standard deviation
 */
public void setData(TsData serie, TsData lower, TsData upper) {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    chartPanel.getChart().setTitle(new TextTitle("Aggregated Data", new Font("SansSerif", Font.PLAIN, 12)));

    plot.setDataset(SMOOTH_INDEX, TsXYDatasets.from("series", serie));
    plot.setDataset(DIFF_INDEX, TsXYDatasets.builder().add("lower", lower).add("upper", upper).build());

    onDataFormatChange();
    onColorSchemeChange();
}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

private JFreeChart createQuestionChart(String title, double[][] values) {
    JFreeChart chart = ChartFactory.createScatterPlot(title, null, null, new MdsXYDataset(values),
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new VectorRenderer());
    plot.setDataset(1, getVectorDataset(values));
    plot.getRenderer().setBaseItemLabelsVisible(true);

    plot.getRenderer().setBaseItemLabelPaint(Color.BLUE);
    plot.getRenderer().setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override/*from   www .j a va 2s .  c o  m*/
        public String generateLabel(XYDataset dataset, int series, int item) {
            //return "#" + (item + 1);
            return "#" + (item + 1) + ":" + Config.INSTANCE.getDitoConfig().getQuestion(item + 1).getName();
        }
    });
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "#" + (item + 1) + ":" + Config.INSTANCE.getDitoConfig().getQuestion(item + 1).getName();
        }
    });
    return chart;
}

From source file:DualAxisDemo2.java

/**
 * A demonstration application showing how to create a time series chart with dual axes.
 *
 * @param title  the frame title.//  w  w w  .  j av  a  2s  . c om
 */
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:ec.nbdemetra.ui.chart3d.functions.Functions2DChart.java

/**
 * Generates the data and displays it in the chart. Calculates the points
 * ("steps" total points) and the optimum of the function
 *//*from w ww  .  ja v  a2 s  .c o  m*/
public void generateData() {
    if (function == null || maxFunction == null) {
        throw new IllegalArgumentException("The given functions can't be null !");
    }

    BasicXYDataset dataset = new BasicXYDataset();
    BasicXYDataset optimumDataset = new BasicXYDataset();
    double[] dataX = new double[steps];
    double[] dataY = new double[steps];

    final IReadDataBlock parameters = maxFunction.getParameters();
    DataBlock p = new DataBlock(parameters);
    final IParametersDomain d = function.getDomain();

    float xMin = ((float) p.get(0) - epsilon);
    double dMin = d.lbound(0);
    if (DescriptiveStatistics.isFinite(dMin) && xMin < dMin)
        xMin = (float) dMin;
    float xMax = ((float) p.get(0) + epsilon);
    double dMax = d.ubound(0);
    if (DescriptiveStatistics.isFinite(dMax) && xMax > dMax)
        xMax = (float) dMax;
    float stepX = (xMax - xMin) / (steps - 1); // Calculates the "distance" between each point

    // Optimum point of the max likelihood function
    double optiX = parameters.get(0);
    double optiY = maxFunction.getValue();

    for (int i = 0; i < steps; i++) {
        // Value on the x axis (min X value + index* (distance between points)
        float x = xMin + i * stepX;
        float y = Float.NaN;
        p.set(0, x); // Setting new value of the 1st param (X)

        // Calculating the Y value
        try {
            if (d.checkBoundaries(p)) {
                y = (float) function.evaluate(p).getValue();
            }
        } catch (Exception err) {
            y = Float.NaN;
        }

        if (Float.isInfinite(y)) {
            y = Float.NaN;
        }

        dataX[i] = x;
        dataY[i] = y;
    }

    // Creates the 2 datasets (function + optimum point)
    BasicXYDataset.Series serie = BasicXYDataset.Series.of("f(" + d.getDescription(0) + ")", dataX, dataY);
    BasicXYDataset.Series optimum = BasicXYDataset.Series.of("Optimum", new double[] { optiX },
            new double[] { optiY });
    dataset.addSeries(serie);
    optimumDataset.addSeries(optimum);

    XYPlot plot = chart.getXYPlot();
    configureAxis(plot);
    plot.setDataset(0, dataset);
    plot.setDataset(1, optimumDataset);

    panel.setChart(chart);
    add(panel, BorderLayout.CENTER);

    onColorSchemeChange();
}

From source file:org.jfree.chart.demo.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 . ja  va  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.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  .ja  v  a 2  s  . 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;
}