List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries
public void addSeries(XYSeries series)
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); }//www . j ava 2s . c o 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.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); }// w w w .ja va2 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("Average calculate count summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); averageCalculateCountSummaryChartFile = writeChartToImageFile(chart, "averageCalculateCountSummary"); }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * Some basic checks for the removeSeries() method. *///from w ww .ja va 2s. co m public void testRemoveSeries() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); c.removeSeries(0); assertEquals(0, c.getSeriesCount()); c.addSeries(s1); boolean pass = false; try { c.removeSeries(-1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { c.removeSeries(1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset./* www .ja va 2 s .c o m*/ */ private static XYDataset[] createDataset(List<Schedule> schedules, HashMap<VirtualCommodity, PriceSignal> ps, HashMap<VirtualCommodity, PowerLimitSignal> pls, long currentTime) { XYSeriesCollection dataset1 = new XYSeriesCollection(); //power axis if (pls != null) { for (Entry<VirtualCommodity, PowerLimitSignal> e : pls.entrySet()) { long time = (long) ((currentTime / 86400.0) * 86400); PowerLimitSignal currentPls = e.getValue(); XYSeries upperLimit = new XYSeries(e.getKey().getCommodity() + "_upper_limit"); XYSeries lowerLimit = new XYSeries(e.getKey().getCommodity() + "_lower_limit"); while (currentPls != null && currentPls.getNextPowerLimitChange(time) != null) { upperLimit.add(time * 1000, currentPls.getPowerUpperLimit(time)); lowerLimit.add(time * 1000, currentPls.getPowerLowerLimit(time)); time = currentPls.getNextPowerLimitChange(time); upperLimit.add((time - 1) * 1000, currentPls.getPowerUpperLimit(time - 1)); lowerLimit.add((time - 1) * 1000, currentPls.getPowerLowerLimit(time - 1)); } dataset1.addSeries(upperLimit); dataset1.addSeries(lowerLimit); } } XYSeriesCollection dataset2 = new XYSeriesCollection(); //costs axis if (ps != null) { for (Entry<VirtualCommodity, PriceSignal> e : ps.entrySet()) { long time = (long) ((currentTime / 86400.0) * 86400); PriceSignal currentPs = e.getValue(); XYSeries currentxySeries = new XYSeries(e.getKey().getCommodity() + "_price"); while (currentPs != null && currentPs.getNextPriceChange(time) != null) { currentxySeries.add(time * 1000, currentPs.getPrice(time)); time = currentPs.getNextPriceChange(time); currentxySeries.add((time - 1) * 1000, currentPs.getPrice(time - 1)); } dataset2.addSeries(currentxySeries); } } XYSeriesCollection dataset3 = new XYSeriesCollection(); if (schedules != null) { int cntr = 1; SparseLoadProfile powerSum = new SparseLoadProfile(); if (schedules != null) { for (Schedule i : schedules) { XYSeries[] powerProfile = (XYSeries[]) renderSeries(i.getProfile(), Integer.toString(cntr++), currentTime); for (int j = 0; j < powerProfile.length; j++) { dataset3.addSeries(powerProfile[j]); } powerSum = (SparseLoadProfile) powerSum.merge(i.getProfile(), 0); } } XYSeries[] powerProfileSum = (XYSeries[]) renderSeries(powerSum, "sum", currentTime); for (int j = 0; j < powerProfileSum.length; j++) { dataset3.addSeries(powerProfileSum[j]); } } return new XYDataset[] { dataset1, dataset2, dataset3 }; }
From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartLineGraphicCreator.java
private XYDataset createEmptyDataset() { emptyDataset = true;// w w w .ja v a 2 s .c o m XYSeriesCollection xysc = new XYSeriesCollection(); XYSeries xys = new XYSeries(""); xys.add(fromDate.getTime(), null); xys.add(toDate.getTime(), null); xysc.addSeries(xys); return xysc; }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. *///from ww w . ja v a 2s . c om @Test public void testSerialization() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeriesCollection c2 = (XYSeriesCollection) TestUtilities.serialised(c1); assertEquals(c1, c2); }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Confirm that cloning works./*from ww w . j ava 2 s . c o m*/ */ @Test public void testCloning() throws CloneNotSupportedException { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeriesCollection c2 = (XYSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); }
From source file:mil.tatrc.physiology.utilities.csv.plots.CSVPlotTool.java
public void createGraph(String toDir, Paint color, String title, String XAxisLabel, String YAxisLabel, XYSeries... xyData) {//ww w. j a v a 2s . co m new File(toDir).mkdir(); Log.info("Creating Graph " + toDir + "/" + title); double resMin0 = 1.e6; double resMax0 = -1.e6; double resMin1 = 1.e6; double resMax1 = -1.e6; XYSeriesCollection dataSet = new XYSeriesCollection(); for (XYSeries data : xyData) { if (data != null && !data.isEmpty()) dataSet.addSeries(data); } JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title XAxisLabel, // x axis label YAxisLabel, // y axis label dataSet, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); /* I have residual and error plots turned off, there are some plots that contain these names in their title, and I don't want this code running, need a better way to see if we are doing a special plot rather than title contents if(title.contains("Residual")) { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); if (Math.abs(xyData[0].getMinY()) > Math.abs(xyData[0].getMaxY())) resMax0 = Math.abs(resMin0); if (Math.abs(xyData[0].getMaxY()) > Math.abs(xyData[0].getMinY())) resMin0 = -1.0*Math.abs(resMax0); if((resMin0==0.0) && (resMax0==0.0)) { resMin0 = -0.00001; resMax0 = 0.00001; } ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05*resMin0, resMax0 + 0.05*resMax0);//5% buffer so we can see top and bottom clearly } else if(title.contains("Error")) { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); if((resMin0==0.0) && (resMax0==0.0)) { resMin0 = -0.00001; resMax0 = 0.00001; } if(resMin0>=0.0) resMin0 = -0.01; ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05*resMin0, resMax0 + 0.05*resMax0);//5% buffer so we can see top and bottom clearly /* yAxis.setTickLabelPaint(new Color(1,0,0)); yAxis.setTickMarkPaint(new Color(1,0,0)); yAxis.setAxisLinePaint(new Color(1,0,0)); yAxis.setLabelPaint(new Color(1,0,0)); ValueAxis xAxis = plot.getDomainAxis(); xAxis.setTickLabelPaint(new Color(1,0,0)); xAxis.setTickMarkPaint(new Color(1,0,0)); yAxis.setAxisLinePaint(new Color(1,0,0)); yAxis.setLabelPaint(new Color(1,0,0)); * } else */ { if (title.indexOf("Hemoglobin-GlomerularFilterability") > -1) System.out.println("stop"); if (xyData.length > 1) { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); resMax1 = xyData[1].getMaxY(); resMin1 = xyData[1].getMinY(); if (resMin1 < resMin0) resMin0 = resMin1; if (resMax1 > resMax0) resMax0 = resMax1; if (DoubleUtils.isZero(resMin0)) resMin0 = -0.001; if (DoubleUtils.isZero(resMax0)) resMax0 = 0.001; if (resMin0 >= 0.0) resMin0 = -0.01; if (YAxisLabel.indexOf("PlasmaConcentration") > -1) plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")")); else { ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.15 * Math.abs(resMax0));//5% buffer so we can see top and bottom clearly } String NaNCheck = ""; if (Double.isNaN(resMax0) || Double.isNaN(resMin0)) NaNCheck += "Expected is NaN "; if (Double.isNaN(resMax1) || Double.isNaN(resMin1)) NaNCheck += "Computed is NaN "; if (!NaNCheck.isEmpty()) plot.getDomainAxis().setLabel(NaNCheck); } else { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); if (Double.isNaN(resMax0) || Double.isNaN(resMin0)) plot.getDomainAxis().setLabel("Computed is NaN"); if (DoubleUtils.isZero(resMin0)) resMin0 = -0.001; if (DoubleUtils.isZero(resMax0)) resMax0 = 0.001; if (resMin0 >= 0.0) resMin0 = -0.01; if (YAxisLabel.indexOf("PlasmaConcentration") > -1) plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")")); else { ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.15 * Math.abs(resMax0));//5% buffer so we can see top and bottom clearly } } } formatXYPlot(chart, color); //Changing line widths and colors XYItemRenderer r = plot.getRenderer(); BasicStroke wideLine = new BasicStroke(lineWidth); r.setSeriesStroke(0, wideLine); r.setSeriesStroke(1, wideLine); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); if (xyData.length > 1) { renderer.setSeriesStroke(//makes a dashed line 0, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K) new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 15.0f, 30.0f }, 0.0f)); renderer.setDrawSeriesLineAsPath(true); renderer.setUseFillPaint(true); } renderer.setBaseShapesVisible(false); renderer.setSeriesFillPaint(0, expectedLineColor); renderer.setSeriesFillPaint(1, computedLineColor); renderer.setSeriesPaint(0, expectedLineColor); renderer.setSeriesPaint(1, computedLineColor); try { if (toDir == null || toDir.isEmpty()) toDir = "."; File JPGFile = new File(toDir + "/" + MakeFileName(title) + ".jpg"); ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800); } catch (IOException e) { Log.error(e.getMessage()); } }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * A test for bug report 1170825./*w w w . jav a 2 s .c om*/ */ @Test public void test1170825() { XYSeries s1 = new XYSeries("Series1"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); } catch (IllegalArgumentException e) { // correct outcome } catch (IndexOutOfBoundsException e) { assertTrue(false); // wrong outcome } }
From source file:net.footballpredictions.footballstats.swing.GoalsGraph.java
/** * Plot goals scored and conceded against number of matches played. *//* ww w . ja v a 2 s . com*/ public void updateGraph(String teamName, LeagueSeason data) { XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries forSeries = new XYSeries(teamName + ' ' + messageResources.getString("graphs.scored")); XYSeries againstSeries = new XYSeries(teamName + ' ' + messageResources.getString("graphs.conceded")); int[][] goals = data.getTeam(teamName).getGoalsData(); for (int i = 0; i < goals.length; i++) { forSeries.add(i, goals[i][0]); againstSeries.add(i, goals[i][1]); } dataSet.addSeries(forSeries); dataSet.addSeries(againstSeries); JFreeChart chart = ChartFactory.createXYLineChart(null, // Title messageResources.getString("graphs.matches"), messageResources.getString("combo.GraphType.GOALS"), dataSet, PlotOrientation.VERTICAL, true, // Legend. false, // Tooltips. false); // URLs. chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int max = Math.max(goals[goals.length - 1][0], goals[goals.length - 1][1]); chart.getXYPlot().getRangeAxis().setRange(0, max + 1); XYDifferenceRenderer renderer = new XYDifferenceRenderer(); renderer.setSeriesPaint(0, Colours.POSITIVE); // Green. renderer.setPositivePaint(Colours.POSITIVE_FILL); // Translucent green. renderer.setSeriesPaint(1, Colours.NEGATIVE); // Red. renderer.setNegativePaint(Colours.NEGATIVE_FILL); // Translucent red. chart.getXYPlot().setRenderer(renderer); setChart(chart); }