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); }
JFreeChart chart = // your chart chart.removeLegend(); LegendTitle legend = new LegendTitle(new LineLegendItemSource()); chart.addLegend(legend);
public String createChart(DesignOptions options, ChartRenderingInfo renderingInfo) throws Exception { Map<String, OXFFeatureCollection> entireCollMap = getFeatureCollectionFor(options, true); JFreeChart chart = producePresentation(entireCollMap, options); chart.removeLegend(); String chartFileName = createAndSaveImage(options, chart, renderingInfo); return ConfigurationContext.IMAGE_SERVICE + chartFileName; }
/** * @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 improveChart(JFreeChart jfrechart, ChartParameters params) { Color background = Color.decode("#" + params.getValue(ChartParameters.PARAM_BACKGROUND_COLOR, "FFFFFF", false)); jfrechart.setBackgroundPaint(background); jfrechart.setBorderVisible(false); jfrechart.setAntiAlias(true); jfrechart.setTextAntiAlias(true); jfrechart.removeLegend(); }
public void createChartToOutputStream(DesignOptions options, ChartRenderingInfo renderingInfo, OutputStream outputStream) { try { Map<String, OXFFeatureCollection> entireCollMap = getFeatureCollectionFor(options, true); JFreeChart chart = producePresentation(entireCollMap, options); chart.removeLegend(); int width = options.getWidth(); int height = options.getHeight(); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height, renderingInfo); } catch (Exception e) { LOGGER.warn("Error while rendering chart.", e); } }
/** * Creates a new plot. * * @param dataset the dataset ({@code null} permitted). */ public MultiplePiePlot(CategoryDataset dataset) { super(); setDataset(dataset); PiePlot piePlot = new PiePlot(null); piePlot.setIgnoreNullValues(true); this.pieChart = new JFreeChart(piePlot); this.pieChart.removeLegend(); this.dataExtractOrder = TableOrder.BY_COLUMN; this.pieChart.setBackgroundPaint(null); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); this.pieChart.setTitle(seriesTitle); this.aggregatedItemsKey = "Other"; this.aggregatedItemsPaint = Color.lightGray; this.sectionPaints = new HashMap(); this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0); }
/** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). */ public MultiplePiePlot(CategoryDataset dataset) { super(); setDataset(dataset); PiePlot piePlot = new PiePlot(null); piePlot.setIgnoreNullValues(true); this.pieChart = new JFreeChart(piePlot); this.pieChart.removeLegend(); this.dataExtractOrder = TableOrder.BY_COLUMN; this.pieChart.setBackgroundPaint(null); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); this.pieChart.setTitle(seriesTitle); this.aggregatedItemsKey = "Other"; this.aggregatedItemsPaint = Color.lightGray; this.sectionPaints = new HashMap(); this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0); }
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); }
@Override protected JFreeChart createGraph() { TimeTableXYDataset dataset = createDataset(); ValueAxis xAxis = new DateAxis(); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); Calendar lowerBound = getLowerGraphBound(); xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis()); NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL); yAxis.setRange(0, HUNDRED_PERCENT); XYItemRenderer renderer = new XYBarRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.removeLegend(); return chart; }
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; }
private JFreeChart createAmountChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "", // title resourceMap.getString("graphDate.text"), // x-axis label resourceMap.getString("graphCBills.text"), // y-axis label dataset); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setDefaultShapesVisible(true); renderer.setDefaultShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); chart.removeLegend(); return chart; }
public JFreeChart createStackedBarChart(String title, XYDataset dataset) { DateAxis domainAxis = new DateAxis("Date"); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis rangeAxis = new NumberAxis("Hours"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // leave some space for item labels StackedXYBarRenderer renderer = new StackedXYBarRenderer(0.15); // StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0"))); XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(title, plot); chart.removeLegend(); chart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); LegendTitle legend = new LegendTitle(plot); legend.setBackgroundPaint(Color.white); legend.setFrame(new BlockBorder()); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); return chart; }
/** * Creates a sparkline chart. * * @return A sparkline chart. */ private static JFreeChart createSparklineChart() { GXYPlot plot = new GXYPlot(); plot.setInsets(RectangleInsets.ZERO_INSETS); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(plot); chart.setPadding(RectangleInsets.ZERO_INSETS); chart.removeLegend(); chart.setBackgroundPaint(Color.white); renderer.setBasePaint(new Color(0xFF9900)); renderer.setBaseStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setAutoPopulateSeriesPaint(false); GValueAxis xAxis = new GValueAxis(); xAxis.setVisible(false); plot.setDomainAxis(xAxis); GValueAxis yAxis = new GValueAxis(); yAxis.setVisible(false); plot.setRangeAxis(yAxis); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return chart; }
private JFreeChart getGaugeChart( BaseChart chart, ValueDataset dataSet ) { MeterPlot meterPlot = new MeterPlot( dataSet ); meterPlot.setUnits( "" ); meterPlot.setRange( new Range( 0.0d, 100d ) ); for ( int i = 0; i < 10; i++ ) { double start = i * 10d; double end = start + 10d; String label = String.valueOf( start ); meterPlot.addInterval( new MeterInterval( label, new Range( start, end ), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY ) ); } meterPlot.setMeterAngle(180); meterPlot.setDialBackgroundPaint( COLOR_LIGHT_GRAY ); meterPlot.setDialShape( DialShape.CHORD ); meterPlot.setNeedlePaint( COLORS[0] ); meterPlot.setTickLabelsVisible( true ); meterPlot.setTickLabelFont( LABEL_FONT ); meterPlot.setTickLabelPaint( Color.BLACK ); meterPlot.setTickPaint( COLOR_LIGHTER_GRAY ); meterPlot.setValueFont( TITLE_FONT ); meterPlot.setValuePaint( Color.BLACK ); JFreeChart meterChart = new JFreeChart( chart.getName(), meterPlot ); setBasicConfig( meterChart, chart ); meterChart.removeLegend(); return meterChart; }
private void createUI() { plot = new XYImagePlot(); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); domainAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); rangeAxis.setUpperMargin(0); rangeAxis.setLowerMargin(0); plot.setNoDataMessage(NO_DATA_MESSAGE); plot.getRenderer().setBaseToolTipGenerator(new XYPlotToolTipGenerator()); JFreeChart chart = new JFreeChart(CHART_TITLE, plot); ChartFactory.getChartTheme().apply(chart); chart.removeLegend(); createUI(createChartPanel(chart), createOptionsPanel(), bindingContext); updateUIState(); }
private void createUI() { plot = new XYImagePlot(); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); domainAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); rangeAxis.setUpperMargin(0); rangeAxis.setLowerMargin(0); plot.setNoDataMessage(NO_DATA_MESSAGE); plot.getRenderer().setBaseToolTipGenerator(new XYPlotToolTipGenerator()); JFreeChart chart = new JFreeChart(CHART_TITLE, plot); ChartFactory.getChartTheme().apply(chart); chart.removeLegend(); createUI(createChartPanel(chart), createOptionsPanel(), bindingContext); updateUIState(); }