List of usage examples for org.jfree.chart.plot XYPlot setDataset
public void setDataset(int index, XYDataset dataset)
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
public static JFreeChart createOverlaidOHLCAndStepChart(TimePeriodValuesCollection bottom, TimePeriodValuesCollection top, OHLCDataset ohlCdata) { DateAxis xAxis = new DateAxis(null); NumberAxis yAxis = new NumberAxis("price"); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); yAxis.setUpperBound(100);/*from w w w .j a v a 2s . co m*/ yAxis.setLowerBound(0.0); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setDataset(0, bottom); plot.setDataset(1, top); plot.setDataset(2, ohlCdata); XYStepAreaRenderer bottomRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null); XYStepAreaRenderer topRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null); HighLowRenderer hiLoRenderer = new HighLowRenderer(); topRenderer.setRangeBase(1.0); topRenderer.setSeriesPaint(0, new Color(204, 255, 153)); bottomRenderer.setSeriesPaint(0, new Color(51, 255, 204)); plot.setRenderer(bottomRenderer); plot.setRenderer(1, topRenderer); plot.setRenderer(2, hiLoRenderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java
/** * Create and display an overlaid chart. * //from w ww.jav a 2 s.co m * @param frameTitle * the frame title. * @param data1 * dataset1. * @param data2 * dataset2. */ private static void displayYSymbolicOverlaid(final String frameTitle, final XYDataset data1, final XYDataset data2) { final String title = "Animals Overlaid"; final String xAxisLabel = "Miles"; final String yAxisLabel = "Animal"; // combine the y symbolic values of the two data sets... final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2); // make master dataset... final CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final XYDataset series2 = new SubSeriesDataset(data, 2); final XYDataset series3 = new SubSeriesDataset(data, 3); final XYDataset series4 = new SubSeriesDataset(data, 4); final XYDataset series5 = new SubSeriesDataset(data, 5); final XYDataset series6 = new SubSeriesDataset(data, 6); final XYDataset series7 = new SubSeriesDataset(data, 7); // create main plot... final ValueAxis valueAxis = new NumberAxis(xAxisLabel); final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer); plot.setDataset(1, series1); final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(1, renderer1); plot.setDataset(2, series2); final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(2, renderer2); plot.setDataset(3, series3); final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(3, renderer3); plot.setDataset(4, series4); final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(4, renderer4); plot.setDataset(5, series5); final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(5, renderer5); plot.setDataset(6, series6); final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(6, renderer6); plot.setDataset(7, series7); final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setRenderer(7, renderer7); // make the chart... final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); // and present it in a frame... final JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Modify a scatter plot to show linear regression or not. * @param scatterPlot Scatter plot to modify * @param enabled Indicates if linear regression has to be shown */// ww w .ja v a 2s. c om public static void setScatterPlotLinearRegressionEnabled(final JFreeChart scatterPlot, final boolean enabled) { XYPlot plot = (XYPlot) scatterPlot.getPlot(); if (enabled) { StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer(); regressionRenderer.setBaseSeriesVisibleInLegend(false); plot.setDataset(1, regress((XYSeriesCollection) plot.getDataset(0))); plot.setRenderer(1, regressionRenderer); } else { plot.setDataset(1, null);//Remove linear regression } }
From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java
/** * Displays an overlaid XYPlot with X and Y symbolic data. * // w ww.j a v a 2 s . com * @param frameTitle * the frame title. * @param data1 * the dataset 1. * @param data2 * the dataset 2. */ private static void displayXYSymbolicOverlaid(final String frameTitle, final XYDataset data1, final XYDataset data2) { final String title = "Pollutant Overlaid"; final String xAxisLabel = "Contamination and Type"; final String yAxisLabel = "Pollutant"; // combine the x symbolic values of the two data sets final String[] combinedXSymbolicValues = SampleXYSymbolicDataset .combineXSymbolicDataset((XisSymbolic) data1, (XisSymbolic) data2); // combine the y symbolic values of the two data sets final String[] combinedYSymbolicValues = SampleXYSymbolicDataset .combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2); // make master dataset... final CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); // create overlaid plot... final SymbolicAxis hsymbolicAxis = new SymbolicAxis(xAxisLabel, combinedXSymbolicValues); final SymbolicAxis vsymbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues); final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot plot = new XYPlot(series0, hsymbolicAxis, vsymbolicAxis, renderer1); final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); plot.setDataset(1, series1); plot.setRenderer(1, renderer2); // make the chart... final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); // and present it in a frame... final JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); }
From source file:org.jfree.chart.demo.HighLowChartDemo3.java
private static JFreeChart createChart(OHLCDataset ohlcdataset) { JFreeChart jfreechart = ChartFactory.createHighLowChart("OHLC Demo 3", "Time", "Price", ohlcdataset, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); HighLowRenderer highlowrenderer = (HighLowRenderer) xyplot.getRenderer(); highlowrenderer.setBaseStroke(new BasicStroke(2.0F)); highlowrenderer.setSeriesPaint(0, Color.blue); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); NumberAxis numberaxis1 = new NumberAxis("Price 2"); numberaxis1.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createDataset2()); xyplot.setRenderer(1, new CandlestickRenderer(10D)); xyplot.mapDatasetToRangeAxis(1, 1);/*from w ww . j ava2 s . c o m*/ ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport.java
public static JFreeChart[] createRegressionCharts(JFreeChart[] t_ScatterPlots, Object[] t_RegressionParametersAndXYLineCharts) throws IOException { JFreeChart[] result = new JFreeChart[t_ScatterPlots.length]; Object[] t_RegressionParameters = (Object[]) t_RegressionParametersAndXYLineCharts[0]; JFreeChart[] t_regressionXYLineCharts = (JFreeChart[]) t_RegressionParametersAndXYLineCharts[1]; JFreeChart[] t_yequalsxXYLineCharts = (JFreeChart[]) t_RegressionParametersAndXYLineCharts[2]; for (int i = 0; i < result.length; i++) { double[] a_RegressionParameters = (double[]) t_RegressionParameters[i]; int maxLengthOfIntString = 6; String b = String.valueOf(a_RegressionParameters[0]); String a = String.valueOf(a_RegressionParameters[1]); String rsquare = String.valueOf(a_RegressionParameters[2]); String title = "Y=" + a.substring(0, Math.min(a.length(), maxLengthOfIntString)) + "X"; if (a_RegressionParameters[0] < 0) { title += b.substring(0, Math.min(b.length(), maxLengthOfIntString)); } else {/*w w w . ja v a 2 s . c o m*/ title += "+" + b.substring(0, Math.min(b.length(), maxLengthOfIntString)); } if (a_RegressionParameters.length > 2) { title += " RSquare " + rsquare.substring(0, Math.min(rsquare.length(), maxLengthOfIntString)); } XYLineAndShapeRenderer points_XYLineAndShapeRenderer = new XYLineAndShapeRenderer(false, true); XYPlot a_ScatterPlotXYPlot = (XYPlot) t_ScatterPlots[i].getPlot(); a_ScatterPlotXYPlot.setDataset(0, a_ScatterPlotXYPlot.getDataset()); points_XYLineAndShapeRenderer.setSeriesPaint(0, Color.blue); //Shape[] _Shapes = DefaultDrawingSupplier.createStandardSeriesShapes(); // System.out.println("There are " + _Shapes.length + // " number of Shapes to try..."); // 0 are square // 1 are circles // 2 are up-pointing triangle // 3 are diamond // 4 are horizontal rectangle // 5 are down-pointing triangle // 6 are horizontal ellipse // 7 are right-pointing triangle // 8 are vertical rectangle // 9 are left-pointing triangle int a_SpikeLength = 3; int[] xpoints = new int[9]; int[] ypoints = new int[9]; xpoints[0] = 0; ypoints[0] = 0; xpoints[1] = 0; ypoints[1] = a_SpikeLength; xpoints[2] = 0; ypoints[2] = 0; xpoints[3] = a_SpikeLength; ypoints[3] = 0; xpoints[4] = 0; ypoints[4] = 0; xpoints[5] = 0; ypoints[5] = -a_SpikeLength; xpoints[6] = 0; ypoints[6] = 0; xpoints[7] = -a_SpikeLength; ypoints[7] = 0; xpoints[8] = 0; ypoints[8] = 0; Shape a_Shape = new Polygon(xpoints, ypoints, xpoints.length); // points_XYLineAndShapeRenderer.setSeriesShape( 0, _Shapes[2] ); points_XYLineAndShapeRenderer.setSeriesShape(0, a_Shape); a_ScatterPlotXYPlot.setRenderer(0, points_XYLineAndShapeRenderer); XYDataset a_regressionXYLineChartXYDataset = ((XYPlot) t_regressionXYLineCharts[i].getPlot()) .getDataset(); XYLineAndShapeRenderer line_XYLineAndShapeRenderer = new XYLineAndShapeRenderer(true, false); a_ScatterPlotXYPlot.setDataset(1, a_regressionXYLineChartXYDataset); line_XYLineAndShapeRenderer.setPaint(Color.red); a_ScatterPlotXYPlot.setRenderer(1, line_XYLineAndShapeRenderer); XYDataset a_yequalsxXYLineChartXYDataset = ((XYPlot) t_yequalsxXYLineCharts[i].getPlot()).getDataset(); XYLineAndShapeRenderer yequalsxline_XYLineAndShapeRenderer = new XYLineAndShapeRenderer(true, false); a_ScatterPlotXYPlot.setDataset(2, a_yequalsxXYLineChartXYDataset); yequalsxline_XYLineAndShapeRenderer.setPaint(Color.green); a_ScatterPlotXYPlot.setRenderer(2, yequalsxline_XYLineAndShapeRenderer); result[i] = new JFreeChart(title, a_ScatterPlotXYPlot); } return result; }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
private static void fillWithMultipleAxis(final Instances dataSet, final int dateIdx, final TimeSeriesCollection tsDataset, final JFreeChart tsChart) { final int numInstances = dataSet.numInstances(); int axisNumber = 0; final Calendar cal = Calendar.getInstance(); for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) { final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name()); for (int k = 0; k < numInstances; k++) { final long timeInMilliSec = (long) dataSet.instance(k).value(dateIdx); cal.setTimeInMillis(timeInMilliSec); if (dataSet.instance(k).isMissing(i)) { ts.addOrUpdate(new Millisecond(cal.getTime()), null); } else { ts.addOrUpdate(new Millisecond(cal.getTime()), dataSet.instance(k).value(i)); }/*from ww w . jav a 2s. c o m*/ } if (!ts.isEmpty()) { if (axisNumber == 0) { tsDataset.addSeries(ts); } else { final XYPlot plot = tsChart.getXYPlot(); final NumberAxis axisToAdd = new NumberAxis(dataSet.attribute(i).name()); axisToAdd.setAutoRangeIncludesZero(false); plot.setRangeAxis(axisNumber, axisToAdd); final TimeSeriesCollection t = new TimeSeriesCollection(); t.addSeries(ts); plot.setDataset(axisNumber, t); plot.mapDatasetToRangeAxis(axisNumber, axisNumber); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, ColorHelper.getColorForAString(dataSet.attribute(i).name())); plot.setRenderer(axisNumber, renderer2); } axisNumber++; } } }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
private static JFreeChart priceVolumeHistoryChart(String title, TimePeriodValuesCollection prices, TimePeriodValuesCollection volumes, boolean scalePrices) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, null, "Price", prices, false, false, false); XYPlot plot = chart.getXYPlot(); if (scalePrices) { setBoundsForPrice(chart);/* w w w . j a va 2 s. c om*/ } else { setBoundsForPercent(chart); } NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(2); plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, volumes); plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer2 = new XYBarRenderer(0.2); plot.setRenderer(1, renderer2); return chart; }
From source file:temp1.RealTimeChart.java
public static JFreeChart createChart(String chartContent, String title, String yaxisName) { thread1 = new Thread(); timeseries1 = new TimeSeries(chartContent, Millisecond.class); timeseries2 = new TimeSeries(chartContent, Millisecond.class); timeseries3 = new TimeSeries(chartContent, Millisecond.class); timeseries4 = new TimeSeries(chartContent, Millisecond.class); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1); TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2); TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3); TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4); jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false); final XYPlot xyplot = jfreechart.getXYPlot(); xyplot.setOutlinePaint(Color.magenta); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.gray); xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true);/*from w ww.j a va 2 s . co m*/ valueaxis.setFixedAutoRange(20000D); //Value valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(800D, 3300D); xyplot.setDataset(0, timeseriescollection); xyplot.setDataset(1, timeseriescollection1); xyplot.setDataset(2, timeseriescollection2); xyplot.setDataset(3, timeseriescollection3); XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer(); xylineandshaperenderer0.setBaseShapesVisible(false); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer3.setBaseShapesVisible(false); xylineandshaperenderer0.setSeriesPaint(0, Color.RED); xylineandshaperenderer1.setSeriesPaint(0, Color.cyan); xylineandshaperenderer2.setSeriesPaint(0, Color.yellow); xylineandshaperenderer3.setSeriesPaint(0, Color.blue); xyplot.setRenderer(0, xylineandshaperenderer0); xyplot.setRenderer(1, xylineandshaperenderer1); xyplot.setRenderer(2, xylineandshaperenderer2); xyplot.setRenderer(3, xylineandshaperenderer3); //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F)); return jfreechart; }
From source file:ec.ui.view.DistributionView.java
private static JFreeChart createDistributionViewChart() { XYPlot plot = new XYPlot(); XYLineAndShapeRenderer dRenderer = new XYSplineRenderer(); dRenderer.setBaseShapesVisible(false); dRenderer.setAutoPopulateSeriesPaint(false); dRenderer.setAutoPopulateSeriesStroke(false); dRenderer.setBaseStroke(TsCharts.getStrongStroke(LinesThickness.Thin)); dRenderer.setDrawSeriesLineAsPath(true); // not sure if useful plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset()); plot.setRenderer(DISTRIBUTION_INDEX, dRenderer); XYBarRenderer hRenderer = new XYBarRenderer(); hRenderer.setShadowVisible(false);/*from ww w . j av a 2s .c o m*/ hRenderer.setDrawBarOutline(true); hRenderer.setAutoPopulateSeriesPaint(false); hRenderer.setAutoPopulateSeriesOutlinePaint(false); hRenderer.setBaseSeriesVisibleInLegend(false); plot.setDataset(HISTOGRAM_INDEX, Charts.emptyXYDataset()); plot.setRenderer(HISTOGRAM_INDEX, hRenderer); NumberAxis domainAxis = new NumberAxis(); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); plot.setDomainGridlinesVisible(false); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); rangeAxis.setTickUnit(new NumberTickUnit(0.05)); rangeAxis.setNumberFormatOverride(new DecimalFormat("0.###")); plot.setRangeAxis(rangeAxis); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); JFreeChart result = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); result.setPadding(TsCharts.CHART_PADDING); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); result.getLegend().setFrame(BlockBorder.NONE); result.getLegend().setBackgroundPaint(null); return result; }