private BufferedImage plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title) { log.info("plot to {}", pngFile); XYSeriesCollection problem; XYSeriesCollection solution = null; final XYSeriesCollection shipments; try { retrieveActivities(vrp); problem = new XYSeriesCollection(activities); shipments = makeShipmentSeries(vrp.getJobs().values()); if (routes != null) solution = makeSolutionSeries(vrp, routes); } catch (NoLocationFoundException e) { log.warn("cannot plot vrp, since coord is missing"); return null; } final XYPlot plot = createPlot(problem, shipments, solution); JFreeChart chart = new JFreeChart(title, plot); LegendTitle legend = createLegend(routes, shipments, plot); chart.removeLegend(); chart.addLegend(legend); save(chart, pngFile); return chart.createBufferedImage(1024, 1024); }
public void addLegend(LegendTitle legend) { legend.setItemFont(new Font("SansSerif", Font.PLAIN, 22)); graph.addLegend(legend); }
JFreeChart chart = // your chart chart.removeLegend(); LegendTitle legend = new LegendTitle(new LineLegendItemSource()); chart.addLegend(legend);
/** * @param showLegend <code>true</code> if the legend is to be shown. */ public void setShowLegend(boolean showLegend) { this.showLegend = showLegend; if(showLegend) { chart.addLegend(createLegend(chart.getPlot())); } else { chart.removeLegend(); } }
private void setLegend(JFreeChart chart) { chart.removeLegend(); final LegendTitle legend = new LegendTitle(new SpectrumLegendItemSource()); legend.setPosition(RectangleEdge.BOTTOM); LineBorder border = new LineBorder(Color.BLACK, new BasicStroke(), new RectangleInsets(2, 2, 2, 2)); legend.setFrame(border); chart.addLegend(legend); }
private void setLegend(JFreeChart chart) { chart.removeLegend(); final LegendTitle legend = new LegendTitle(new SpectrumLegendItemSource()); legend.setPosition(RectangleEdge.BOTTOM); LineBorder border = new LineBorder(Color.BLACK, new BasicStroke(), new RectangleInsets(2, 2, 2, 2)); legend.setFrame(border); chart.addLegend(legend); }
private void plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title) { log.info("plot to {}", pngFile); XYSeriesCollection problem; XYSeriesCollection solution = null; final XYSeriesCollection shipments; try { retrieveActivities(vrp); problem = new XYSeriesCollection(activities); shipments = makeShipmentSeries(vrp.getJobs().values()); if (routes != null) solution = makeSolutionSeries(vrp, routes); } catch (NoLocationFoundException e) { log.warn("cannot plot vrp, since coord is missing"); return; } final XYPlot plot = createPlot(problem, shipments, solution); JFreeChart chart = new JFreeChart(title, plot); LegendTitle legend = createLegend(routes, shipments, plot); chart.removeLegend(); chart.addLegend(legend); save(chart, pngFile); }
private static JFreeChart createChart() { CombinedDomainXYPlot localCombinedDomainXYPlot = new CombinedDomainXYPlot(new DateAxis("Time")); JFreeChart localJFreeChart = new JFreeChart("Sample", localCombinedDomainXYPlot); localCombinedDomainXYPlot.add(createSubplot1(createDataset1()), 1); ChartUtilities.applyCurrentTheme(localJFreeChart); localJFreeChart.setBackgroundPaint(Color.white); final LegendItemCollection legendItemsOld = localCombinedDomainXYPlot.getLegendItems(); LegendItemSource source = new LegendItemSource() { public LegendItemCollection getLegendItems() { LegendItemCollection lic = new LegendItemCollection(); int itemCount = legendItemsOld.getItemCount(); for (int i = 0; i < itemCount; i++) { lic.add(legendItemsOld.get(i)); } return lic; } }; localJFreeChart.removeLegend(); localJFreeChart.addLegend(new LegendTitle(source)); localJFreeChart.getLegend().setPosition(RectangleEdge.TOP); localJFreeChart.getLegend().getItemContainer().getBlocks(); return localJFreeChart; }
chart.addLegend(createLegend(plot));
chart.addLegend(createLegend(plot));