/** * Draws a chart into {@link JFreeChart}. */ public JFreeChart createChart() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused null, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); chart.getLegend().setItemFont(CHART_FONT); final CategoryPlot plot = chart.getCategoryPlot(); configurePlot(plot); configureRangeAxis((NumberAxis) plot.getRangeAxis()); crop(plot); return chart; }
final JFreeChart chart = ChartFactory.createLineChart(null, // chart title ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(3)); configureRenderer(renderer); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
/** * Renders a clickable map. */ public void doMap(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.checkIfModified(timestamp, rsp)) return; ChartRenderingInfo info = new ChartRenderingInfo(); render(req,info); rsp.setContentType("text/plain;charset=UTF-8"); rsp.getWriter().println(ChartUtilities.getImageMap( "map", info )); } }
final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRenderer(ar); plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
private BufferedImage render(StaplerRequest req, ChartRenderingInfo info) { String w = req.getParameter("width"); if(w==null) w=String.valueOf(defaultW); String h = req.getParameter("height"); if(h==null) h=String.valueOf(defaultH); Color graphBg = stringToColor(req.getParameter("graphBg")); Color plotBg = stringToColor(req.getParameter("plotBg")); if (graph==null) graph = createGraph(); graph.setBackgroundPaint(graphBg); Plot p = graph.getPlot(); p.setBackgroundPaint(plotBg); return graph.createBufferedImage(Integer.parseInt(w),Integer.parseInt(h),info); }
private JFreeChart createChart(CheapTimeSolution solution) { TangoColorFactory tangoColorFactory = new TangoColorFactory(); NumberAxis rangeAxis = new NumberAxis("Period"); rangeAxis.setRange(-0.5, solution.getGlobalPeriodRangeTo() + 0.5); XYPlot taskAssignmentPlot = createTaskAssignmentPlot(tangoColorFactory, solution); XYPlot periodCostPlot = createPeriodCostPlot(tangoColorFactory, solution); XYPlot capacityPlot = createAvailableCapacityPlot(tangoColorFactory, solution); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(rangeAxis); combinedPlot.add(taskAssignmentPlot, 5); combinedPlot.add(periodCostPlot, 1); combinedPlot.add(capacityPlot, 1); combinedPlot.setOrientation(PlotOrientation.HORIZONTAL); return new JFreeChart("Cheap Power Time Scheduling", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); }
"Problem scale", NumberFormat.getInstance(locale), "Best " + scoreLevelLabel, NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart( "Best " + scoreLevelLabel + " scalability summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
@Override public void resetPanel(Schedule schedule) { removeAll(); ChartPanel chartPanel = new ChartPanel(createChart(schedule)); add(chartPanel, BorderLayout.CENTER); }
public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) { DefaultPieDataset dataset = new DefaultPieDataset(); Iterator iter = jsonData.keys(); while (iter.hasNext()) { String keyData = (String)iter.next(); Float value = Float.parseFloat(jsonData.getString(keyData)); dataset.setValue(keyData, value); } boolean legend = legendBit; boolean tooltips = tooltipBit; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.BLACK); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); return chart; } }
public static void writeChartToImageFile(JFreeChart chart, File chartFile) { BufferedImage chartImage = chart.createBufferedImage(1024, 768); try (OutputStream out = new FileOutputStream(chartFile)) { ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Failed writing chartFile (" + chartFile + ").", e); } }
ChartUtilities.writeChartAsPNG(outputStream, chart, width, height);
private void writeScoreCalculationSpeedSummaryChart() { List<XYSeries> seriesList = new ArrayList<>(plannerBenchmarkResult.getSolverBenchmarkResultList().size()); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult.getSingleBenchmarkResultList()) { if (singleBenchmarkResult.hasAllSuccess()) { long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale(); long scoreCalculationSpeed = singleBenchmarkResult.getScoreCalculationSpeed(); series.add((Long) problemScale, (Long) scoreCalculationSpeed); } } seriesList.add(series); } XYPlot plot = createScalabilityPlot(seriesList, "Problem scale", NumberFormat.getInstance(locale), "Score calculation speed per second", NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Score calculation speed summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); scoreCalculationSpeedSummaryChartFile = writeChartToImageFile(chart, "scoreCalculationSpeedSummary"); }
@Override public void resetPanel(CheapTimeSolution solution) { removeAll(); add(groupByMachineCheckBox, BorderLayout.NORTH); ChartPanel chartPanel = new ChartPanel(createChart(solution)); add(chartPanel, BorderLayout.CENTER); }
private File writeChartToImageFile(JFreeChart chart, String fileNameBase) { BufferedImage chartImage = chart.createBufferedImage(1024, 768); File summaryChartFile = new File(summaryDirectory, fileNameBase + ".png"); try (OutputStream out = new FileOutputStream(summaryChartFile)) { ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Failed writing summaryChartFile (" + summaryChartFile + ").", e); } return summaryChartFile; }
CategoryPlot plot = createBarChartPlot(dataset, "Winning " + scoreLevelLabel + " difference", NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Winning " + scoreLevelLabel + " difference summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); winningScoreDifferenceSummaryChartFileList.add(
private void writeBestScoreSummaryChart() { // Each scoreLevel has its own dataset and chartFile List<DefaultCategoryDataset> datasetList = new ArrayList<>(CHARTED_SCORE_LEVEL_SIZE); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult.getSingleBenchmarkResultList()) { String problemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName(); if (singleBenchmarkResult.hasAllSuccess()) { double[] levelValues = ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getAverageScore()); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= datasetList.size()) { datasetList.add(new DefaultCategoryDataset()); } datasetList.get(i).addValue(levelValues[i], solverLabel, problemLabel); } } } } bestScoreSummaryChartFileList = new ArrayList<>(datasetList.size()); int scoreLevelIndex = 0; for (DefaultCategoryDataset dataset : datasetList) { String scoreLevelLabel = plannerBenchmarkResult.findScoreLevelLabel(scoreLevelIndex); CategoryPlot plot = createBarChartPlot(dataset, "Best " + scoreLevelLabel, NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Best " + scoreLevelLabel + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); bestScoreSummaryChartFileList.add(writeChartToImageFile(chart, "bestScoreSummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }
"Worst " + scoreLevelLabel + " difference percentage", NumberFormat.getPercentInstance(locale)); JFreeChart chart = new JFreeChart("Worst " + scoreLevelLabel + " difference percentage" + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
private void writeTimeSpentScalabilitySummaryChart() { List<XYSeries> seriesList = new ArrayList<>(plannerBenchmarkResult.getSolverBenchmarkResultList().size()); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult.getSingleBenchmarkResultList()) { if (singleBenchmarkResult.hasAllSuccess()) { long problemScale = singleBenchmarkResult.getProblemBenchmarkResult().getProblemScale(); long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent(); series.add((Long) problemScale, (Long) timeMillisSpent); } } seriesList.add(series); } XYPlot plot = createScalabilityPlot(seriesList, "Problem scale", NumberFormat.getInstance(locale), "Time spent", new MillisecondsSpentNumberFormat(locale)); JFreeChart chart = new JFreeChart("Time spent scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); timeSpentScalabilitySummaryChartFile = writeChartToImageFile(chart, "timeSpentScalabilitySummary"); }
private void writeWorstScoreCalculationSpeedDifferencePercentageSummaryChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult.getSingleBenchmarkResultList()) { String problemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName(); if (singleBenchmarkResult.hasAllSuccess()) { double worstScoreCalculationSpeedDifferencePercentage = singleBenchmarkResult.getWorstScoreCalculationSpeedDifferencePercentage(); dataset.addValue(worstScoreCalculationSpeedDifferencePercentage, solverLabel, problemLabel); } } } CategoryPlot plot = createBarChartPlot(dataset, "Worst score calculation speed difference percentage", NumberFormat.getPercentInstance(locale)); JFreeChart chart = new JFreeChart("Worst score calculation speed difference percentage" + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); worstScoreCalculationSpeedDifferencePercentageSummaryChartFile = writeChartToImageFile(chart, "worstScoreCalculationSpeedDifferencePercentageSummary"); }
private void writeTimeSpentSummaryChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult.getSingleBenchmarkResultList()) { String problemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName(); if (singleBenchmarkResult.hasAllSuccess()) { long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent(); dataset.addValue(timeMillisSpent, solverLabel, problemLabel); } } } CategoryPlot plot = createBarChartPlot(dataset, "Time spent", new MillisecondsSpentNumberFormat(locale)); JFreeChart chart = new JFreeChart("Time spent summary (lower time is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); timeSpentSummaryChartFile = writeChartToImageFile(chart, "timeSpentSummary"); }