/** * Utility method to set the default style of the Area Charts * * @param chart {@link JFreeChart} to style */ private static void setAreaChartDefaults(JFreeChart chart) { ChartUtil.setDefaults(chart); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // renderer AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setBaseItemLabelFont(ChartDefaults.defaultFont); renderer.setBaseItemLabelPaint(ChartDefaults.axisLabelColor); for (int j = 0; j < ChartDefaults.darkColors.length; j++) { renderer.setSeriesPaint(j, ChartDefaults.darkColors[j]); } }
/** * Generates an area chart from the incoming dataset and stores the image for viewing. * * @param dataset is a jfreechart collection containing the issues in a form that the * charting tool understands. * @param chartTitle identifies the title to be used on the generated chart. * @param yLabel identifies the label to use on the generated charts y-axis. * @param xLabel identifies the label to use on the generated charts x-axis. * @return a string containing the filename of the generated chart. */ public static ChartHelper generateAreaChart(CategoryDataset dataset, String chartTitle, String yLabel, String xLabel) { boolean legend = false; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createAreaChart(chartTitle, yLabel, xLabel, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBackgroundPaint(Color.WHITE); chart.setBorderVisible(false); CategoryPlot plot = chart.getCategoryPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); TickUnitSource units = NumberAxis.createIntegerTickUnits(); axis.setStandardTickUnits(units); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, COLOR_RED_PAINT); renderer.setSeriesOutlinePaint(0, new Color(255, 0, 0)); renderer.setSeriesOutlineStroke(0, new BasicStroke(1f)); renderer.setSeriesStroke(0, new BasicStroke(3f)); return new ChartHelper(chart); }