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.fr3ts0n.ecu.gui.application.ObdDataPlotter.java

/**
 * remove all data series from graph object
 *///from w  w w . j a v a2s.c  o m
public synchronized void removeAllSeries() {
    dataset.removeAllSeries();
    if (oneRangePerSeries) {
        XYPlot plot = (XYPlot) chart.getPlot();
        for (; raIndex > 0; raIndex--) {
            plot.setDataset(raIndex, null);
            plot.setRenderer(raIndex, null);
            plot.setRangeAxis(raIndex, null);
        }
        plot.setDataset(dataset);
    }
}

From source file:GeMSE.Visualization.ElbowPlot.java

public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) {
    double maxY = 0;

    float[] secYColor = new float[3];
    Color.RGBtoHSB(153, 245, 255, secYColor);

    float[] priYColor = new float[3];
    Color.RGBtoHSB(255, 255, 255, priYColor);

    float[] cutColor = new float[3];
    Color.RGBtoHSB(255, 255, 0, cutColor);

    //create the series - add some dummy data
    XYSeries pvSeries = new XYSeries("Percentage of variance        ");
    for (int i = 1; i < pvData.size(); i++) {
        pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]);
        maxY = Math.max(maxY, pvData.get(i)[1]);
    }/*from ww  w . j  a  v a  2 s  . c  om*/

    XYSeries dSeries = new XYSeries("Percentage of differences between slopes        ");
    for (int i = 0; i < dData.size(); i++)
        dSeries.add(dData.get(i)[0], dData.get(i)[1]);

    XYSeries cutSeries = new XYSeries("Cut        ");
    cutSeries.add(cut, 0.0);
    cutSeries.add(cut, maxY);

    //create the datasets
    XYSeriesCollection pvDataSeries = new XYSeriesCollection();
    pvDataSeries.addSeries(pvSeries);

    XYSeriesCollection cutDataSeries = new XYSeriesCollection();
    cutDataSeries.addSeries(cutSeries);

    XYSeriesCollection dDataSeries = new XYSeriesCollection();
    dDataSeries.addSeries(dSeries);

    //construct the plot
    XYPlot plot = new XYPlot();
    plot.setDataset(0, pvDataSeries);
    plot.setDataset(1, cutDataSeries);
    plot.setDataset(2, dDataSeries);

    // use XYSplineRenderer if you want to smooth the lines.
    XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer();
    pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));

    BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 1.0f, 10.0f }, 0.0f);
    XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer();
    dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    dRenderer.setSeriesStroke(0, dstroke);

    BasicStroke cutStoke = new BasicStroke(4);
    // use XYSplineRenderer if you want to smooth the lines.
    //XYSplineRenderer cutRenderer = new XYSplineRenderer();
    XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer();
    cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2]));
    cutRenderer.setSeriesStroke(0, cutStoke);

    plot.setRenderer(0, pvRenderer);
    plot.setRenderer(1, cutRenderer);
    plot.setRenderer(2, dRenderer);

    plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance"));
    plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes"));
    plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n"));

    //Map the data to the appropriate axis
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 0);
    plot.mapDatasetToRangeAxis(2, 1);

    float[] hsbValues = new float[3];
    Color.RGBtoHSB(16, 23, 67, hsbValues);
    plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));

    Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14);
    Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12);
    Font legendFont = new Font("Dialog", Font.PLAIN, 14);

    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(axisLabelFont);
    plot.getDomainAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelFont(axisLabelFont);
    plot.getRangeAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelFont(axisLabelFont);
    plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont);

    //generate the chart
    JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(),
            plot, true);

    chart.getTitle().setPaint(Color.white);
    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setItemFont(legendFont);

    float[] hsbValues2 = new float[3];
    Color.RGBtoHSB(36, 43, 87, hsbValues2);
    chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2]));
    JPanel chartPanel = new ChartPanel(chart);

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    chartPanel.setPreferredSize(
            new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0),
                    (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0)));

    setContentPane(chartPanel);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java

public void setGatingData(ArrayList<Integer> delays) {
    final XYSeries s1 = new XYSeries("delays");
    for (Integer delay : delays) {
        s1.add((double) delay, 0);
    }//from   w  ww. j  a v a2  s . c o  m
    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    rawGateData_ = delays;
    gatePositionData_ = dataset;
    XYPlot plot = chart_.getXYPlot();
    plot.setDataset(1, gatePositionData_);
}

From source file:graph.MySensorPanel.java

/**
 * Creates a new self-contained demo panel.
 *//*from ww  w. java2  s  .  c  om*/
public MySensorPanel(String header_str) {
    //super(new BorderLayout());
    this.series1 = new TimeSeries("Temperature");
    this.series2 = new TimeSeries("Humidity");
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(header_str, "Time", "C", dataset1, true, true,
            false);

    /*this.addChart(chart);*/

    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(1000.0 * 60 * 60 /* 24*/); // 24 hrs

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

    ChartUtilities.applyCurrentTheme(chart);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    chartPanel = new ChartPanel(chart);
}

From source file:ui.Graph.java

/**
 * Creates a chart.//from ww w . ja  v  a2s. c  o m
 *
 * @param dataset
 *            the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(ArrayList<Setpoint> setpoints, ArrayList<Setpoint> traj) {
    trajectory = traj;

    XYSeries posSeries = new XYSeries("Position");
    XYSeries trajSeries = new XYSeries("Trajectory");
    XYSeries velSeries = new XYSeries("Velocity");
    for (int i = 0; i < setpoints.size(); i++) {

        Setpoint p = setpoints.get(i);
        posSeries.add(p.time, p.position);
        velSeries.add(p.time, p.velocity);
    }

    for (int i = 0; i < trajectory.size(); i++) {

        Setpoint p = trajectory.get(i);
        trajSeries.add(p.time, p.position);

    }

    XYSeriesCollection posDataset = new XYSeriesCollection();
    XYSeriesCollection trajDataset = new XYSeriesCollection();
    XYSeriesCollection velDataset = new XYSeriesCollection();

    posDataset.addSeries(posSeries);
    velDataset.addSeries(velSeries);
    trajDataset.addSeries(trajSeries);
    // create the chart...
    final JFreeChart chart = ChartFactory.createScatterPlot("System output", // chart title
            "X", // x axis label
            "Y", // y axis label
            posDataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

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

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();

    plot.setDataset(0, posDataset);
    plot.setDataset(1, trajDataset);
    plot.setDataset(2, velDataset);
    plot.setBackgroundPaint(Color.white);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer posRenderer = new XYLineAndShapeRenderer();
    // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f,
    // 1.0f));
    posRenderer.setSeriesPaint(0, Color.BLUE);
    posRenderer.setSeriesLinesVisible(0, true);
    posRenderer.setSeriesShapesVisible(0, false);
    XYStepRenderer trajRenderer = new XYStepRenderer();
    trajRenderer.setSeriesPaint(1, Color.RED);
    trajRenderer.setSeriesStroke(1, new BasicStroke(10));
    trajRenderer.setSeriesLinesVisible(1, true);
    trajRenderer.setSeriesShapesVisible(1, false);

    XYLineAndShapeRenderer velRenderer = new XYLineAndShapeRenderer();
    velRenderer.setSeriesPaint(0, Color.MAGENTA);
    velRenderer.setSeriesLinesVisible(0, true);
    velRenderer.setSeriesShapesVisible(0, false);
    // renderer.setSeriesStroke(1, new BasicStroke(0.01f));
    plot.setRenderer(0, posRenderer);
    plot.setRenderer(1, trajRenderer);
    plot.setRenderer(2, velRenderer);

    for (Setpoint s : trajectory) {
        Marker marker = new ValueMarker(s.time);
        marker.setPaint(Color.DARK_GRAY);
        marker.setLabel(Float.toString((float) s.position));
        marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(marker);
    }

    XYTextAnnotation p = new XYTextAnnotation("kP = " + gains.kP, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .75);
    p.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(p);
    XYTextAnnotation i = new XYTextAnnotation("kI = " + gains.kI, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .7);
    i.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(i);
    XYTextAnnotation d = new XYTextAnnotation("kD = " + gains.kD, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .65);
    d.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(d);

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

    return chart;

}

From source file:edu.cmu.sv.modelinference.eventtool.EventVisualizer.java

private void visualizeFeatures(ClassificationResult classes, Map<EventClass, Color> clusterColors,
        List<Range<Integer>> violations, int timeStepSize, DefaultXYDataset rawDataSet,
        DefaultXYDataset featuresDataSet) {

    //Get chart on which we will plot the features and violations
    DataChart c = new DataChart("Features chart");
    JFreeChart chart = c.chart("");

    //Plot violations
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(0, rawDataSet);
    plot.setRenderer(0, new ClassificationXYRenderer(classes, timeStepSize, clusterColors));

    plot.setDataset(1, featuresDataSet);
    plot.setRenderer(1, new XYLineAndShapeRenderer());

    setViolationMarkers(violations, plot);
    c.pack();//from  w  w  w .jav  a 2s .c  o  m
    RefineryUtilities.centerFrameOnScreen(c);
    c.setVisible(true);
}

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

public TimePeriodValuesDemo1(String s) {
    super(s);//  ww  w  . j av  a 2s. c o  m
    XYDataset xydataset = createDataset1();
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setVerticalTickLabels(true);
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Value");
    XYPlot xyplot = new XYPlot(xydataset, dateaxis, numberaxis, xybarrenderer);
    XYDataset xydataset1 = createDataset2();
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3);
    standardxyitemrenderer.setBaseShapesFilled(true);
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, standardxyitemrenderer);
    JFreeChart jfreechart = new JFreeChart("Supply and Demand", xyplot);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}

From source file:ec.ui.chart.RevisionChartPanel.java

/**
 * Sets the data of the graph//from   w ww.  j a v a2 s  . c  o m
 * @param reference Reference serie used for the revisions
 * @param revisions Calculated list of revision's series
 */
public void setTsData(TsData reference, List<TsData> revisions) {
    this.reference = reference;
    this.revs = revisions;

    TimeSeriesCollection ref = new TimeSeriesCollection();
    addSerie(ref, reference);

    XYPlot plot = panel.getChart().getXYPlot();
    plot.setDataset(REF_INDEX, ref);
    plot.setRenderer(REF_INDEX, refRenderer);
    refRenderer.setSeriesPaint(0, themeSupport.getLineColor(ColorScheme.KnownColor.RED));
    refRenderer.setSeriesStroke(0, new BasicStroke(2.0f));

    TimeSeriesCollection revCol = null;
    if (revisions != null && !revisions.isEmpty()) {
        revCol = new TimeSeriesCollection();
        for (TsData t : revisions) {
            addSerie(revCol, t);
        }

        plot.setDataset(SERIES_INDEX, revCol);
        plot.setRenderer(SERIES_INDEX, seriesRenderer);
        for (int i = 0; i < revCol.getSeriesCount(); i++) {
            seriesRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE));
            seriesRenderer.setSeriesStroke(i, new BasicStroke(0.75f));
        }
    } else {
        plot.setDataset(SERIES_INDEX, Charts.emptyXYDataset());
        refRenderer.setSeriesPaint(0, themeSupport.getLineColor(ColorScheme.KnownColor.ORANGE));
    }

    configureAxis(plot);

    setRange(ref, revCol);
}

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

/**
 * Add the data set as the second axis to this chart
 *///from  w  w w .  j a va  2 s. c  o  m
public void addSecondAxis(JFreeChart chart, Options options) {
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(1, getDataset());
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis rangeAxis2 = new NumberAxis(options.getSecondAxisChartYAxisTitle());
    plot.setRangeAxis(1, rangeAxis2);

    // need a separate renderer for the axis, otherwise the same colours are used as for the first axis series
    setAxisRenderer(chart.getXYPlot(), 1, options.isSecondAxisBarChart(), options.hasSecondAxisDataPoints(),
            options.getSecondAxisLineWeight());

    setAxisLimits(rangeAxis2, options.getSecondAxisMinYValue(), options.getSecondAxisMaxYValue(),
            options.forceSecondAxisYRange());

    rangeAxis2.setAutoRangeIncludesZero(false);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java

public void acqMaxpointData() {
    ArrayList<Integer> signal = new ArrayList<Integer>();
    ArrayList<Integer> delays = new ArrayList<Integer>();

    // instrument interacting fn, currently dummy
    // REMEMBER TO APPLY THRESHOLD

    // plot maxpoint data
    findMaxpointData_ = createDummyMaxpointData(0);
    XYPlot plot = chart_.getXYPlot();
    plot.setDataset(0, findMaxpointData_);

    // assign maxpoint - easier when this is real data...
    ArrayList<XYDataItem> dummy = new ArrayList<XYDataItem>(
            ((XYSeriesCollection) findMaxpointData_).getSeries(0).getItems());
    for (XYDataItem dummy1 : dummy) {
        delays.add((Integer) dummy1.getX().intValue());
        signal.add((Integer) dummy1.getY().intValue());
    }/*from ww  w  .  j a  va2  s  . c o  m*/

    int[] res = findMaxIndex(signal);
    maxpointDelay_ = delays.get(res[0]);

    // estimate lifetime
    signal = new ArrayList<Integer>(signal.subList(res[0], signal.size()));
    delays = new ArrayList<Integer>(delays.subList(res[0], delays.size()));
    double sumt2 = 0;
    double sumt = 0;
    double sumtlnI = 0;
    double sumlnI = 0;

    for (int i = 0; i < signal.size(); i++) {

        sumt2 = sumt2 + delays.get(i) * delays.get(i);
        sumt = sumt + delays.get(i);
        sumlnI = (sumlnI + log((double) signal.get(i)));
        sumtlnI = sumtlnI + log((double) signal.get(i)) * delays.get(i);

    }

    lifetime_ = -(delays.size() * sumt2 - sumt * sumt) / (delays.size() * sumtlnI - sumt * sumlnI);

}