public void createLineChart(final String filename) { LineChart chart = new LineChart(TITLE, X_AXIS, Y_AXIS, new String[] {"A", "B", "C"}); chart.addSeries(SERIE_1, new double[] {1.0, 5.0, 2.0, 3.0, 4.5}); chart.addSeries(SERIE_2, new double[] {2.0, 3.0, 3.0, 1.5, 4.5}); chart.saveAsPng(filename, 800, 600); }
public void createXYLogLogLineChart(final String filename) { XYLineChart chart = new XYLineChart(TITLE, X_AXIS, Y_AXIS, true); chart.addSeries(SERIE_1, new double[] {1.0, 2.0, 3.0, 4.0, 5.0}, new double[] {1.0, 5.0, 2.0, 3.0, 4.5}); chart.addSeries(SERIE_2, new double[] {1.0, 5.0, 2.0, 4.0, 3.0}, new double[] {2.0, 3.0, 3.0, 1.5, 4.5}); chart.saveAsPng(filename, 800, 600); }
public void createBarChart(final String filename) { BarChart chart = new BarChart(TITLE, X_AXIS, Y_AXIS, new String[] {"A", "B", "C"}); chart.addSeries(SERIE_1, new double[] {1.0, 5.0, 2.0, 3.0, 4.5}); chart.addSeries(SERIE_2, new double[] {2.0, 3.0, 3.0, 1.5, 4.5}); chart.addMatsimLogo(); chart.saveAsPng(filename, 800, 600); }
private void dropChart( final Id groupId, final History history) { final XYLineChart chart = new XYLineChart( getStatName()+" Statistics for "+groupId, "iteration", getStatName()); chart.addSeries( "avg. minimum "+getStatName(), history.getIterations(), history.getAvgOfMinimums()); chart.addSeries( "avg. max "+getStatName(), history.getIterations(), history.getAvgOfMaximums()); chart.addSeries( "avg. of plans' average "+getStatName(), history.getIterations(), history.getAvgOfAverages()); chart.addSeries( "avg. executed "+getStatName(), history.getIterations(), history.getAvgOfExecuted()); chart.addMatsimLogo(); chart.saveAsPng(this.fileName + "_" + groupId + ".png", 800, 600); }
public static void main(final String[] args) { log.info("start to write demo charts..."); Demo demo = new Demo(); demo.createBarChart("./output/barchart.png"); demo.createStackedBarChart("./output/stackedbarchart.png"); demo.createLineChart("./output/linechart.png"); demo.createXYLineChart("./output/xylinechart.png"); demo.createXYLogLogLineChart("./output/xylineloglogchart.png"); demo.createXYScatterChart("./output/xyscatterchart.png"); log.info("charts written to output directory at ./output/!"); } }
private void addSeriesToPlot(int index, XYLineChart xyLineChart, double[] iterations, int series) { double[] values = new double[index + 1]; System.arraycopy(this.history[series], 0, values, 0, index + 1); xyLineChart.addSeries(INDEX.values()[series].enName, iterations, values); }
/** * Test that a file was really generated, and that the image, when loaded, has the specified size. * @throws IOException possible exception when reading the image for validation */ public void testXYScatterChartDemo() throws IOException { String imageFilename = getOutputDirectory() + "xyscatterchart.png"; Demo demo = new Demo(); demo.createXYScatterChart(imageFilename); File imagefile = new File(imageFilename); assertTrue(imagefile.exists()); BufferedImage image = ImageIO.read(imagefile); assertEquals(800, image.getWidth(null)); assertEquals(600, image.getHeight(null)); }
/** * Test that a file was really generated, and that the image, when loaded, has the specified size. * @throws IOException possible exception when reading the image for validation */ public void testXYLineChartDemo() throws IOException { String imageFilename = getOutputDirectory() + "xylinechart.png"; Demo demo = new Demo(); demo.createXYLineChart(imageFilename); File imagefile = new File(imageFilename); assertTrue(imagefile.exists()); BufferedImage image = ImageIO.read(imagefile); assertEquals(800, image.getWidth(null)); assertEquals(600, image.getHeight(null)); }
/** * Test that a file was really generated, and that the image, when loaded, has the specified size. * @throws IOException possible exception when reading the image for validation */ public void testLineChartDemo() throws IOException { String imageFilename = getOutputDirectory() + "linechart.png"; Demo demo = new Demo(); demo.createLineChart(imageFilename); File imagefile = new File(imageFilename); assertTrue(imagefile.exists()); BufferedImage image = ImageIO.read(imagefile); assertEquals(800, image.getWidth(null)); assertEquals(600, image.getHeight(null)); }
/** * Test that a file was really generated, and that the image, when loaded, has the specified size. * @throws IOException possible exception when reading the image for validation */ public void testBarChartDemo() throws IOException { System.setProperty("java.awt.headless", "true"); String imageFilename = getOutputDirectory() + "barchart.png"; Demo demo = new Demo(); demo.createBarChart(imageFilename); File imagefile = new File(imageFilename); assertTrue(imagefile.exists()); BufferedImage image = ImageIO.read(imagefile); assertEquals(800, image.getWidth(null)); assertEquals(600, image.getHeight(null)); }
public void createStackedBarChart(final String filename) { StackedBarChart chart = new StackedBarChart(TITLE, X_AXIS, Y_AXIS, new String[] {"A", "B", "C"}); chart.addSeries(SERIE_1, new double[] {1.0, 5.0, 2.0, 3.0, 4.5}); chart.addSeries(SERIE_2, new double[] {2.0, 3.0, 3.0, 1.5, 4.5}); chart.addMatsimLogo(); chart.saveAsPng(filename, 800, 600); }
public void createXYScatterChart(final String filename) { XYScatterChart chart = new XYScatterChart(TITLE, X_AXIS, Y_AXIS); chart.addSeries(SERIE_1, new double[] {1.0, 2.0, 3.0, 4.0, 5.0}, new double[] {1.0, 5.0, 2.0, 3.0, 4.5}); chart.addSeries(SERIE_2, new double[] {1.0, 5.0, 2.0, 4.0, 3.0}, new double[] {2.0, 3.0, 3.0, 1.5, 4.5}); chart.saveAsPng(filename, 800, 600); }
public XYLineChart(final String title, final String xAxisLabel, final String yAxisLabel, boolean isLogarithmicAxis) { super(title, xAxisLabel, yAxisLabel); this.isLogarithmicAxis = isLogarithmicAxis; this.dataset = new XYSeriesCollection(); this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset); addDefaultFormatting(); }
public XYScatterChart(final String title, final String xAxisLabel, final String yAxisLabel, boolean isLogarithmicAxis) { super(title, xAxisLabel, yAxisLabel); this.isLogarithmicAxis = isLogarithmicAxis; this.dataset = new XYSeriesCollection(); this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset); addDefaultFormatting(); }
/** * Creates a new BarChart with the specified category-labels. * * @param title * @param xAxisLabel * @param yAxisLabel * @param categories */ public LineChart(final String title, final String xAxisLabel, final String yAxisLabel, final String[] categories) { super(title, xAxisLabel, yAxisLabel); this.dataset = new DefaultCategoryDataset(); this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset); this.categories = categories.clone(); addDefaultFormatting(); }
/** * Creates a new BarChart with the specified category-labels. * * @param title * @param xAxisLabel * @param yAxisLabel * @param categories */ public BarChart(final String title, final String xAxisLabel, final String yAxisLabel, final String[] categories) { super(title, xAxisLabel, yAxisLabel); this.dataset = new DefaultCategoryDataset(); this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset); this.plot = this.chart.getCategoryPlot(); this.categories = categories.clone(); addDefaultFormatting(); // leave a gap of 20% between categories (groups of bars) final CategoryAxis axis1 = this.plot.getDomainAxis(); axis1.setCategoryMargin(0.20); // leave a gap of 10% between individual bars within one category BarRenderer renderer = (BarRenderer)this.plot.getRenderer(); renderer.setItemMargin(0.10); }
/** * Creates a new BarChart with the specified category-labels. * * @param title * @param xAxisLabel * @param yAxisLabel * @param categories */ public StackedBarChart(final String title, final String xAxisLabel, final String yAxisLabel, final String[] categories) { super(title, xAxisLabel, yAxisLabel); this.dataset = new DefaultCategoryDataset(); this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset); this.plot = this.chart.getCategoryPlot(); this.categories = categories.clone(); addDefaultFormatting(); // leave a gap of 20% between categories (groups of bars) final CategoryAxis axis1 = this.plot.getDomainAxis(); axis1.setCategoryMargin(0.20); // leave a gap of 10% between individual bars within one category BarRenderer renderer = (BarRenderer)this.plot.getRenderer(); renderer.setItemMargin(0.10); }
/** * Stores the chart as PNG image file. * * @param filename The filename of the resulting PNG file. * @param width The width of the chart. * @param height The height of the chart. */ public void saveAsPng(final String filename, final int width, final int height) { try { ChartUtilities.saveChartAsPNG(new File(filename), getChart(), width, height, null, true, 9); } catch (IOException e) { e.printStackTrace(); } catch ( Exception e ) { e.printStackTrace() ; // I just had an out of bounds error inside the method; don't know what that means but does not feel like a reason // to not continue. kai, apr'30 } }
public void createXYLineChart(final String filename) { XYLineChart chart = new XYLineChart(TITLE, X_AXIS, Y_AXIS); chart.addSeries(SERIE_1, new double[] {1.0, 2.0, 3.0, 4.0, 5.0}, new double[] {1.0, 5.0, 2.0, 3.0, 4.5}); chart.addSeries(SERIE_2, new double[] {1.0, 5.0, 2.0, 4.0, 3.0}, new double[] {2.0, 3.0, 3.0, 1.5, 4.5}); chart.saveAsPng(filename, 800, 600); }