List of usage examples for org.jfree.chart.plot XYPlot setDataset
public void setDataset(int index, XYDataset dataset)
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeScalabilitySummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); NumberAxis yAxis = new NumberAxis("Time spend"); yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }// w w w . j a va 2s. c o m XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemScale(); long timeMillisSpend = singleBenchmark.getTimeMillisSpend(); series.add((Long) problemScale, (Long) timeMillisSpend); } } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); scalabilitySummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "scalabilitySummary.png"); OutputStream out = null; try { out = new FileOutputStream(scalabilitySummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing scalabilitySummaryFile: " + scalabilitySummaryFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * init plot// ww w.j a v a 2 s . c om * * @param plot plot */ protected void initPlot(Plot plot) { XYPlot xyPlot = (XYPlot) plot; int count = xyPlot.getDatasetCount(); for (int i = 0; i < count; i++) { xyPlot.setDataset(i, null); xyPlot.setRenderer(i, null); } xyPlot.clearRangeAxes(); XYDataset dummyDataset = getDummyDataset(); ValueAxis rangeAxis = new FixedWidthNumberAxis(); xyPlot.setRangeAxis(0, rangeAxis, false); xyPlot.setDataset(0, dummyDataset); xyPlot.mapDatasetToRangeAxis(0, 0); xyPlot.setRenderer(0, new XYLineAndShapeRenderer()); }
From source file:org.drools.planner.benchmark.core.statistic.BenchmarkReport.java
private void writeScalabilitySummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); NumberAxis yAxis = new NumberAxis("Time spend"); yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale(); long timeMillisSpend = singleBenchmark.getTimeMillisSpend(); series.add((Long) problemScale, (Long) timeMillisSpend); }/*from w w w .ja v a 2 s. co m*/ } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); scalabilitySummaryChartFile = writeChartToImageFile(chart, "scalabilitySummary"); }
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeAverageCalculateCountPerSecondSummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); NumberAxis yAxis = new NumberAxis("Average calculate count per second"); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }//from w w w . ja v a 2 s . co m XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemScale(); long averageCalculateCountPerSecond = singleBenchmark.getAverageCalculateCountPerSecond(); series.add((Long) problemScale, (Long) averageCalculateCountPerSecond); } } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); averageCalculateCountSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "averageCalculateCountSummary.png"); OutputStream out = null; try { out = new FileOutputStream(averageCalculateCountSummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException( "Problem writing averageCalculateCountSummaryFile: " + averageCalculateCountSummaryFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:org.jfree.chart.demo.MultipleAxisDemo3.java
/** * Creates the demo chart.// w w w .j a va2s. c om * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // DOMAIN AXIS 2 final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(1, xAxis2); plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); // DOMAIN AXIS 3 final NumberAxis xAxis3 = new NumberAxis("Domain Axis 3"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(2, xAxis3); plot.setDomainAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT); // RANGE AXIS 2 final NumberAxis yAxis2 = new NumberAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:org.drools.planner.benchmark.core.statistic.BenchmarkReport.java
private void writeAverageCalculateCountPerSecondSummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); NumberAxis yAxis = new NumberAxis("Average calculate count per second"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale(); long averageCalculateCountPerSecond = singleBenchmark.getAverageCalculateCountPerSecond(); series.add((Long) problemScale, (Long) averageCalculateCountPerSecond); }//www. ja va2 s. com } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); averageCalculateCountSummaryChartFile = writeChartToImageFile(chart, "averageCalculateCountSummary"); }
From source file:org.jfree.chart.demo.PriceVolumeDemo.java
/** * Creates a chart./* w w w . j a v a 2 s.co m*/ * * @return a chart. */ private JFreeChart createChart() { final XYDataset priceData = createPriceDataset(); final String title = "Eurodollar Futures Contract (MAR03)"; final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Date", "Price", priceData, true, true, false); final XYPlot plot = chart.getXYPlot(); final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars final DecimalFormat format = new DecimalFormat("00.00"); rangeAxis1.setNumberFormatOverride(format); final XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); final NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(1.00); // to leave room for price line plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, createVolumeDataset()); plot.setRangeAxis(1, rangeAxis2); plot.mapDatasetToRangeAxis(1, 1); final XYBarRenderer renderer2 = new XYBarRenderer(0.20); renderer2.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); plot.setRenderer(1, renderer2); return chart; }
From source file:org.n52.server.sos.render.DiagramRenderer.java
protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap, String[] observedProperties, ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) { JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title "Date", // x-axis label observedProperties[0], // y-axis label timeSeries.get(0), // data true, // create legend? true, // generate tooltips? false // generate URLs? );/*from w ww . j a v a 2s.c om*/ chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // add additional datasets: DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setRange(begin.getTime(), end.getTime()); axis.setDateFormatOverride(new SimpleDateFormat()); for (int i = 1; i < observedProperties.length; i++) { XYDataset additionalDataset = timeSeries.get(i); plot.setDataset(i, additionalDataset); plot.setRangeAxis(i, new NumberAxis(observedProperties[i])); // plot.getRangeAxis(i).setRange((Double) // overAllSeriesCollection.getMinimum(i), // (Double) overAllSeriesCollection.getMaximum(i)); plot.mapDatasetToRangeAxis(i, i); // plot.getDataset().getXValue(i, i); } return chart; }
From source file:com.charts.FiveYearChart.java
public FiveYearChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);//from w w w. j a v a 2s. c o m rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(900, 400)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.MaxChart.java
public MaxChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/*from w w w . j a v a 2 s . c o m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(900, 400)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }