public static ChartHelper generateStackedBarChart(CategoryDataset dataset, String chartTitle, String yLabel, String xLabel, List domainMarkers) { boolean legend = false; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createStackedBarChart(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); plot.getRenderer().setSeriesOutlinePaint(1, COLOR_YELLOW_OUTLINE); plot.getRenderer().setSeriesPaint(1, COLOR_YELLOW_PAINT); plot.getRenderer().setSeriesOutlinePaint(0, COLOR_CYAN_OUTLINE); plot.getRenderer().setSeriesPaint(0, COLOR_CYAN_PAINT); return new ChartHelper(chart); }
public ChartHelper generateChart() { boolean legend = false; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createStackedBarChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); setStackedBarChartDefaults(chart, i18nBean); CategoryPlot plot = chart.getCategoryPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); TickUnitSource units = NumberAxis.createIntegerTickUnits(); axis.setStandardTickUnits(units); CategoryAxis catAxis = plot.getDomainAxis(); catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.getRenderer().setSeriesOutlinePaint(1, ChartDefaults.GREEN_DIFF); plot.getRenderer().setSeriesPaint(1, ChartDefaults.GREEN_DIFF); plot.getRenderer().setSeriesOutlinePaint(0, ChartDefaults.RED_DIFF); plot.getRenderer().setSeriesPaint(0, ChartDefaults.RED_DIFF); return new ChartHelper(chart); }
public static JFreeChart createStackedBarChart(String title, List<List<Double>> bars, List<String> zoneLabels, String xLabel, String yLabel, ColorTheme theme) { DefaultCategoryDataset ds = new DefaultCategoryDataset(); Integer barId = 0; int maxStack = 0; for (List<Double> bar : bars) { int i = 0; maxStack = Math.max(maxStack, bar.size()); for (double value : bar) { ds.addValue(value, zoneLabels.get(i), barId); i++; } barId++; } JFreeChart chart = ChartFactory.createStackedBarChart(title, xLabel, yLabel, ds, PlotOrientation.VERTICAL, true, false, false); formatColorTheme(chart, theme); formatBars(chart); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setCategoryMargin(0); plot.getDomainAxis().setLowerMargin(0); plot.getDomainAxis().setUpperMargin(0); Color[] colors = generateJetSpectrum(maxStack); for (int i = 0; i < maxStack; i++) { plot.getRenderer().setSeriesPaint(i, colors[i]); plot.getRenderer().setSeriesOutlinePaint(i, Color.white); } return chart; }
/** * Generates a bar chart from the incoming data set 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 generateBarChart(CategoryDataset dataset, String chartTitle, String yLabel, String xLabel) { boolean legend = false; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createBarChart(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); plot.getRenderer().setSeriesOutlinePaint(0, COLOR_GREEN_OUTLINE); plot.getRenderer().setSeriesPaint(0, COLOR_GREEN_PAINT); return new ChartHelper(chart); }