List of usage examples for org.jfree.chart.plot XYPlot setDataset
public void setDataset(int index, XYDataset dataset)
From source file:com.philng.telemetrydisplay.GraphDisplay.java
/** * Create the chart itself with datasets * @param dataset// w ww. jav a2s .co m * @return */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("Telemetry Display", "Time", "Voltage", dataset, true, true, false); final XYPlot plot = result.getXYPlot(); // Add in a new y axis for current ValueAxis currentAxis = new NumberAxis(); currentAxis.setRange(0, 100); currentAxis.setLabel("Current"); plot.setRangeAxis(1, currentAxis); plot.setDataset(1, createDatasetCurrent()); plot.mapDatasetToRangeAxis(1, 1); // Set information for the x axis (time) ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); // Set the information for the voltage axis axis = plot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(0.0, 12.0); 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.GREEN); renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); plot.setRenderer(1, renderer2); return result; }
From source file:com.android.ddmuilib.log.event.DisplayGraph.java
/** * Returns the {@link TimeSeriesCollection} for the occurrence display. If the data set is not * yet created, it is first allocated and set up into the {@link org.jfree.chart.JFreeChart} object. *//*from w w w . j a v a 2s. c om*/ private TimeSeriesCollection getOccurrenceDataSet() { if (mOccurrenceDataSet == null) { mOccurrenceDataSet = new TimeSeriesCollection(); XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setDataset(mDataSetCount, mOccurrenceDataSet); OccurrenceRenderer renderer = new OccurrenceRenderer(); renderer.setBaseShapesVisible(false); xyPlot.setRenderer(mDataSetCount, renderer); mDataSetCount++; } return mOccurrenceDataSet; }
From source file:org.jfree.chart.demo.TimePeriodValuesDemo.java
/** * A demonstration application showing how to.... * * @param title the frame title.//from w w w.j a v a 2 s. com */ public TimePeriodValuesDemo(final String title) { super(title); final XYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new XYBarRenderer(); final DateAxis domainAxis = new DateAxis("Date"); domainAxis.setVerticalTickLabels(true); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1)); domainAxis.setDateFormatOverride(new SimpleDateFormat("hh:mm")); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); final ValueAxis rangeAxis = new NumberAxis("Value"); final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1); final XYDataset data2 = createDataset2(); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES_AND_LINES); renderer2.setShapesFilled(true); plot.setDataset(1, data2); plot.setRenderer(1, renderer2); final JFreeChart chart = new JFreeChart("Supply and Demand", plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); }
From source file:org.sunzoft.sunstock.StockMain.java
protected void addIndexChart(XYPlot xyplot) { NumberAxis localNumberAxis1 = new NumberAxis(""); //localNumberAxis1.setLabelPaint(Color.red); //localNumberAxis1.setTickLabelPaint(Color.red); xyplot.setRangeAxis(1, localNumberAxis1); xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); xyplot.setDataset(1, initIndexData()); xyplot.mapDatasetToRangeAxis(1, 1);/* w w w . j a v a 2s . c o m*/ }
From source file:grafix.graficos.indices.IndiceBollinger.java
@Override public void plotar(final XYPlot plot, final JanelaGraficos janela, final int contador) { float[] color = getCor().getComponents(null); XYDifferenceRenderer r = new XYDifferenceRenderer(new Color(color[0], color[1], color[2], .1f), Color.red, false);// w w w.j av a2 s .c om r.setStroke(new BasicStroke(.75f)); r.setPaint(getCor()); plot.setRenderer(contador, r); plot.setDataset(contador, getDataSet(janela)); }
From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java
/** * * @param track//from ww w. java 2 s. co m */ private void plotConvexHull(Track track) { ConvexHull convexHull = track.getConvexHull(); Iterable<GeometricPoint> cHull = convexHull.getHull(); int M = 0; for (GeometricPoint point : cHull) { M++; } // the hull, in counterclockwise order GeometricPoint[] hull = new GeometricPoint[M]; int m = 0; for (GeometricPoint point : cHull) { hull[m++] = point; } // generate xy coordinates for the points of the hull double[] x = new double[m + 1]; double[] y = new double[m + 1]; for (int i = 0; i < m; i++) { GeometricPoint point = hull[i]; x[i] = point.getX(); y[i] = point.getY(); } // repeat fisrt coordinates at the end, to close the polygon x[m] = hull[0].getX(); y[m] = hull[0].getY(); // dataset for the convex hull XYSeries hullSeries = JFreeChartUtils.generateXYSeries(x, y); XYSeriesCollection hullDataset = new XYSeriesCollection(hullSeries); JFreeChart convexHullChart = ChartFactory.createXYLineChart("convex hull", "x", "y", hullDataset, PlotOrientation.VERTICAL, false, true, false); // dataset for the coordinates Double[][] coordinatesMatrix = track.getCoordinates(); XYSeries coordinatesSeries = JFreeChartUtils.generateXYSeries(coordinatesMatrix); XYSeriesCollection coordinatesDataset = new XYSeriesCollection(coordinatesSeries); // use both datasets for the plot XYPlot xyPlot = convexHullChart.getXYPlot(); xyPlot.setDataset(0, coordinatesDataset); xyPlot.setDataset(1, hullDataset); ChartPanel chartPanel = new ChartPanel(convexHullChart); computationDataPanel.getConvexHullParentPanel().removeAll(); computationDataPanel.getConvexHullParentPanel().add(chartPanel, gridBagConstraints); computationDataPanel.getConvexHullParentPanel().revalidate(); computationDataPanel.getConvexHullParentPanel().repaint(); }
From source file:com.android.ddmuilib.log.event.DisplayGraph.java
/** * Returns a {@link TimeSeriesCollection} for a specific {@link com.android.ddmlib.log.EventValueDescription.ValueType}. * If the data set is not yet created, it is first allocated and set up into the * {@link org.jfree.chart.JFreeChart} object. * @param type the {@link com.android.ddmlib.log.EventValueDescription.ValueType} of the data set. * @param accumulateValues/*w w w . j av a 2s . c o m*/ */ private TimeSeriesCollection getValueDataset(EventValueDescription.ValueType type, boolean accumulateValues) { TimeSeriesCollection dataset = mValueTypeDataSetMap.get(type); if (dataset == null) { // create the data set and store it in the map dataset = new TimeSeriesCollection(); mValueTypeDataSetMap.put(type, dataset); // create the renderer and configure it depending on the ValueType AbstractXYItemRenderer renderer; if (type == EventValueDescription.ValueType.PERCENT && accumulateValues) { renderer = new XYAreaRenderer(); } else { XYLineAndShapeRenderer r = new XYLineAndShapeRenderer(); r.setBaseShapesVisible(type != EventValueDescription.ValueType.PERCENT); renderer = r; } // set both the dataset and the renderer in the plot object. XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setDataset(mDataSetCount, dataset); xyPlot.setRenderer(mDataSetCount, renderer); // put a new axis label, and configure it. NumberAxis axis = new NumberAxis(type.toString()); if (type == EventValueDescription.ValueType.PERCENT) { // force percent range to be (0,100) fixed. axis.setAutoRange(false); axis.setRange(0., 100.); } // for the index, we ignore the occurrence dataset int count = mDataSetCount; if (mOccurrenceDataSet != null) { count--; } xyPlot.setRangeAxis(count, axis); if ((count % 2) == 0) { xyPlot.setRangeAxisLocation(count, AxisLocation.BOTTOM_OR_LEFT); } else { xyPlot.setRangeAxisLocation(count, AxisLocation.TOP_OR_RIGHT); } // now we link the dataset and the axis xyPlot.mapDatasetToRangeAxis(mDataSetCount, count); mDataSetCount++; } return dataset; }
From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {//from w ww. j ava 2 s . co m NumberAxis xAxis = new NumberAxis("X"); xAxis.setRange(mins[0], maxs[0]); NumberAxis yAxis = new NumberAxis("Y"); yAxis.setRange(mins[1], maxs[1]); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1)); renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1)); PaintScale scale = new GrayPaintScale(0, 1.0); renderer.setPaintScale(scale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart("", plot); chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false); NumberAxis scaleAxis = new NumberAxis("Probability (class 0)"); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis); legend.setStripOutlineVisible(false); legend.setSubdivisionCount(20); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.red)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.LEFT); chart.addSubtitle(legend); ChartUtilities.applyCurrentTheme(chart); plot.setDataset(1, xyData); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setBaseLinesVisible(false); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:com.bt.aloha.sipstone.GenGraph.java
private JFreeChart createCombinedChart() { XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond(); XYDataset xydataset = xydatasetArray[0]; final XYDataset percXydataset = xydatasetArray[1]; JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = new NumberAxis("Avg. Response Time"); numberaxis.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis);/*www.ja v a2 s. c o m*/ xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime()); xyplot.mapDatasetToRangeAxis(1, 1); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setShapesFilled(true); } XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); xylineandshaperenderer1.setSeriesPaint(0, Color.black); xylineandshaperenderer1.setBaseShapesVisible(true); xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); xyplot.setRenderer(1, xylineandshaperenderer1); NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis(); timeaxis.setAutoRange(true); timeaxis.setAxisLineVisible(true); LegendTitle legendtitle = new LegendTitle(xyitemrenderer); LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer(); xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset)); xyrenderer.setBaseItemLabelsVisible(true); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void showResults() { if (history_ == null) { return;//from w ww . jav a 2 s . c o m } lastIndexSelected = -1; final TimeSeriesCollection chartSeries = new TimeSeriesCollection(); sRef = history_.referenceSeries(info_); TsPeriodSelector selector = new TsPeriodSelector(); int n = sRef.getDomain().getLength(); int freq = sRef.getDomain().getFrequency().intValue(); int l = years_ * freq + 1; int n0 = n - l; if (n0 < minyears_ * freq) { n0 = minyears_ * freq; } if (n0 < n) { firstPeriod = sRef.getDomain().get(n0); selector.from(sRef.getDomain().get(n0).firstday()); } else { firstPeriod = sRef.getStart(); } addSeries(chartSeries, sRef.select(selector)); final TimeSeriesCollection startSeries = new TimeSeriesCollection(); TsDomain dom = sRef.getDomain(); for (int i = n0; i < n - 1; ++i) { addStart(startSeries, info_, dom.get(i)); } if (startSeries.getSeriesCount() == 0 || chartSeries.getSeriesCount() == 0) { chartpanel_.setChart(mainChart); return; } setRange(chartSeries, startSeries); XYPlot plot = mainChart.getXYPlot(); plot.setDataset(S_INDEX, chartSeries); plot.setDataset(REV_INDEX, startSeries); for (int i = 0; i < startSeries.getSeriesCount(); i++) { revRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6)); revRenderer.setSeriesShapesFilled(i, false); revRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE)); } plot.setRenderer(REV_INDEX, revRenderer); setRange(chartSeries, startSeries); configureAxis(plot); plot.mapDatasetToDomainAxis(S_INDEX, REV_INDEX); plot.mapDatasetToRangeAxis(S_INDEX, REV_INDEX); plot.mapDatasetToDomainAxis(REV_INDEX, REV_INDEX); plot.mapDatasetToRangeAxis(REV_INDEX, REV_INDEX); chartpanel_.setChart(mainChart); showRevisionsDocument(revisions()); }