List of usage examples for org.jfree.chart ChartFactory createStackedBarChart
public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java
/** * Create JFreeChart graph using the supplied parameters. * * @param chartType One of the many chart types. * @param conf Chart configuration// w ww .j ava2s . c om * @param is Inputstream containing chart data * @return Initialized chart or NULL in case of issues. * @throws IOException Thrown when a problem is reported while parsing XML data. */ public static JFreeChart createJFreeChart(String chartType, Configuration conf, InputStream is) throws XPathException { logger.debug("Generating " + chartType); // Currently two dataset types supported CategoryDataset categoryDataset = null; PieDataset pieDataset = null; try { if ("PieChart".equals(chartType) || "PieChart3D".equals(chartType) || "RingChart".equals(chartType)) { logger.debug("Reading XML PieDataset"); pieDataset = DatasetReader.readPieDatasetFromXML(is); } else { logger.debug("Reading XML CategoryDataset"); categoryDataset = DatasetReader.readCategoryDatasetFromXML(is); } } catch (IOException ex) { throw new XPathException(ex.getMessage()); } finally { try { is.close(); } catch (IOException ex) { // } } // Return chart JFreeChart chart = null; // Big chart type switch if ("AreaChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("BarChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createBarChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("BarChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("LineChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createLineChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("LineChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createLineChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("MultiplePieChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createMultiplePieChart(conf.getTitle(), categoryDataset, conf.getOrder(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("MultiplePieChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createMultiplePieChart3D(conf.getTitle(), categoryDataset, conf.getOrder(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("PieChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createPieChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("PieChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createPieChart3D(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("RingChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createRingChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("SpiderWebChart".equalsIgnoreCase(chartType)) { SpiderWebPlot plot = new SpiderWebPlot(categoryDataset); if (conf.isGenerateTooltips()) { plot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } chart = new JFreeChart(conf.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); if (conf.isGenerateLegend()) { LegendTitle legend = new LegendTitle(plot); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); } else { TextTitle subTitle = new TextTitle(" "); subTitle.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(subTitle); } setCategoryChartParameters(chart, conf); } else if ("StackedAreaChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("StackedBarChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedBarChart(conf.getTitle(), conf.getDomainAxisLabel(), conf.getRangeAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("StackedBarChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("WaterfallChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createWaterfallChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else { logger.error("Illegal chartype. Choose one of " + "AreaChart BarChart BarChart3D LineChart LineChart3D " + "MultiplePieChart MultiplePieChart3D PieChart PieChart3D " + "RingChart SpiderWebChart StackedAreaChart StackedBarChart " + "StackedBarChart3D WaterfallChart"); } setCommonParameters(chart, conf); return chart; }
From source file:uk.ac.lkl.cram.ui.chart.LearningExperienceChartMaker.java
/** * Create a chart from the provide category dataset * @return a Chart that can be rendered in a ChartPanel *///from www.j av a2 s . c o m @Override protected JFreeChart createChart() { //Create a horizontal stacked bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs JFreeChart chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset, PlotOrientation.HORIZONTAL, true, true, false); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Remove offsets from the plot plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); //Hide the range lines plot.setRangeGridlinesVisible(false); //Get the renderer for the plot StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer(); //Set the painter for the renderer (nothing fancy) sbRenderer.setBarPainter(new StandardBarPainter()); //sbRenderer.setItemMargin(0.5); //Makes no difference //reduces width of bar as proportion of overall width sbRenderer.setMaximumBarWidth(0.5); //Render the bars as percentages sbRenderer.setRenderAsPercentages(true); //Set the colours for the bars sbRenderer.setSeriesPaint(0, PERSONALISED_COLOR); sbRenderer.setSeriesPaint(1, SOCIAL_COLOR); sbRenderer.setSeriesPaint(2, ONE_SIZE_FOR_ALL_COLOR); //Set the tooltips to render percentages sbRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset cd, int row, int column) { //Only interested in row, as there's only one column //TODO--really inefficient @SuppressWarnings("unchecked") List<Comparable> rows = cd.getRowKeys(); Comparable columnKey = cd.getColumnKey(column); //Sum running total int total = 0; for (Comparable comparable : rows) { total += cd.getValue(comparable, columnKey).intValue(); } //Get the value for the row (in our case the learning type) Comparable rowKey = cd.getRowKey(row); float value = cd.getValue(rowKey, columnKey).floatValue(); //The tooltip is the value of the learning type divided by the total, expressed as a percentage @SuppressWarnings("StringBufferWithoutInitialCapacity") StringBuilder builder = new StringBuilder(); builder.append("<html><center>"); builder.append(cd.getRowKey(row)); builder.append(" ("); builder.append(FORMATTER.format(value / total)); builder.append(")<br/>"); builder.append("Double-click for more"); return builder.toString(); } }); //Hide both axes CategoryAxis categoryAxis = plot.getDomainAxis(); //categoryAxis.setCategoryMargin(0.5D);//Makes no difference categoryAxis.setVisible(false); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setVisible(false); return chart; }
From source file:canreg.client.analysis.Tools.java
public static JFreeChart generateJChart(Collection<CancerCasesCount> casesCounts, String fileName, String header, FileTypes fileType, ChartType chartType, boolean includeOther, boolean legendOn, Double restCount, Double allCount, Color color, String labelsCategoryName) { JFreeChart chart;/*from w w w. ja va2 s .c o m*/ if (chartType == ChartType.PIE) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(1); DefaultPieDataset dataset = new DefaultKeyedValuesDataset(); int position = 0; for (CancerCasesCount count : casesCounts) { dataset.insertValue(position++, count.toString() + " (" + format.format(count.getCount() / allCount * 100) + "%)", count.getCount()); } if (includeOther) { dataset.insertValue(position++, "Other: " + restCount.intValue() + " (" + format.format(restCount / allCount * 100) + "%)", restCount); } chart = ChartFactory.createPieChart(header, dataset, legendOn, false, Locale.getDefault()); Tools.setPiePlotColours(chart, casesCounts.size() + 1, color.brighter()); } else { // assume barchart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CancerCasesCount count : casesCounts) { dataset.addValue(count.getCount(), count.getLabel(), count.toString()); } if (includeOther) { dataset.addValue(restCount.intValue(), "Other", "Other: " + restCount); } chart = ChartFactory.createStackedBarChart(header, labelsCategoryName, "Cases", dataset, PlotOrientation.HORIZONTAL, legendOn, true, false); Tools.setBarPlotColours(chart, casesCounts.size() + 1, color.brighter()); } return chart; }
From source file:treegross.standsimulation.TgGrafik.java
public JFreeChart createChart(Stand st) { // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Start and end of classes int minBar = 24; int maxBar = 0; for (int i = 0; i < 25; i++) { double anz2 = 0; for (int k = 1; k < st.ntrees; k++) { if ((st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0)) anz2 = anz2 + st.tr[k].fac; }/*from w w w .jav a2 s . c o m*/ if (anz2 > 0) { if (minBar > i) minBar = i; if (maxBar < i) maxBar = i; } } for (int i = 0; i < 25; i++) { for (int j = 0; j < st.nspecies; j++) { double anz = 0; for (int k = 0; k < st.ntrees; k++) { if ((st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0) && st.tr[k].code == st.sp[j].code) anz = anz + st.tr[k].fac; } if (anz >= 0 && i >= minBar && i <= maxBar) { Integer m = (5 * i) + 2; dataset.addValue(anz / st.size, st.sp[j].spDef.shortName, m.toString()); } } } // JFreeChart chart = ChartFactory.createStackedBarChart(messages.getString("diameterDistribution"), // chart title messages.getString("dbhClass"), // domain axis label messages.getString("numberOfStems"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = chart.getCategoryPlot(); // plot.setBackgroundPaint(Color.lightGray); // plot.setDomainGridlinePaint(Color.white); // plot.setDomainGridlinesVisible(true); // plot.setRangeGridlinePaint(Color.white); // reenderer StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... for (int i = 0; i < st.nspecies; i++) { // renderer.setSeriesStroke(i,new BasicStroke(1.5f)); // GradientPaint gp2 = new GradientPaint( // 0.0f, 1.5f, Color.red, // 1.0f, 0.5f, Color.green); renderer.setSeriesPaint(i, new Color(st.sp[i].spDef.colorRed, st.sp[i].spDef.colorGreen, st.sp[i].spDef.colorBlue)); // renderer.setSeriesPaint(i, gp2); } return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createStackedBarChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createStackedBarChart("StackedBar Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*www. j a v a 2 s. co m*/ chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); return chart; }
From source file:br.com.OCTur.view.InfograficoController.java
private BufferedImage classificacaoHotel() { DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); for (EntidadeGrafico<Hotel> hotel : hoteis.subList(0, hoteis.size() > 4 ? 4 : hoteis.size())) { for (TipoQuarto tipoQuarto : new TipoQuartoDAO().pegarTodos()) { Orcamento orcamento = new OrcamentoDAO().pegarPorTipoQuartoHotel(tipoQuarto, hotel.getEntidade()); if (orcamento != null) { List<Reserva> reservas = new ReservaDAO().pegarPorOrcamentoInicioFim(orcamento, inicio, fim); double total = 0; for (Reserva reserva : reservas) { long dias = (reserva.getFim().getTime() - reserva.getInicio().getTime()) / 1000 / 60 / 60 / 24;/* ww w. j a v a2 s. c o m*/ if (dias <= 0) { dias = 1; } total += (reserva.getQuarto().getOrcamento().getPreco() * dias); } dcdDados.addValue(total * 100 / hotel.getValue(), tipoQuarto.toString(), hotel.toString()); } } } JFreeChart jFreeChart = ChartFactory.createStackedBarChart("", "", "", dcdDados, PlotOrientation.HORIZONTAL, true, false, false); return jFreeChart.createBufferedImage(365, 251); }
From source file:vis2006.VisGrafik.java
public JFreeChart createChart(Stand st, int speciesCode) { // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Durchmesserhufigkeiten in 5-cm-Klassen bestimmen (Klassenmitten: 7.5 bis max. 152.5) for (int i = 0; i < 30; i++) { for (int j = 0; j < 3; j++) { double anz = 0; double gesamtZahl = 0; for (int k = 0; k < st.ntrees; k++) { if (speciesCode == st.tr[k].code && st.tr[k].fac > 0.0) { if ((st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5)) gesamtZahl = gesamtZahl + st.tr[k].fac; if ((j == 2) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0) && (st.tr[k].crop == true)) anz = anz + st.tr[k].fac; if ((j == 0) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0) && (st.tr[k].crop == false)) anz = anz + st.tr[k].fac; if ((j == 1) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out > 0)) anz = anz + st.tr[k].fac; }/*from w ww.j a v a 2s .com*/ } if (gesamtZahl > 0) { Integer m = (5 * i) + 2; String textcode = ""; if (j == 0) textcode = "verbleibend"; if (j == 1) textcode = "ausscheidend"; if (j == 2) textcode = "Z-Bume"; dataset.addValue(anz / st.size, // Anzahl pro ha textcode, // Gruppe m.toString() + ".5"); // Durchmesserklassenmitte } } } // JFreeChart chart = ChartFactory.createStackedBarChart(messages.getString("diameterDistribution"), // chart title messages.getString("dbhClass"), // domain axis label messages.getString("numberOfStems"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = chart.getCategoryPlot(); // plot.setBackgroundPaint(Color.lightGray); // plot.setDomainGridlinePaint(Color.white); // plot.setDomainGridlinesVisible(true); // plot.setRangeGridlinePaint(Color.white); // reenderer StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesPaint(1, Color.RED); renderer.setSeriesPaint(2, Color.BLUE); //renderer.setMaxBarWidth(0.15); renderer.setMaximumBarWidth(0.15); if (dataset.getColumnCount() > 10) { CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); if (dataset.getColumnCount() < 21) xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); else xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } return chart; }
From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java
/** * Gets the Label Propagation in the graph and creates a chart out of it * //from ww w.j a v a 2 s.co m * @throws IOException */ public void getLabelPropagation() throws IOException { Map<Integer, Map<String, Integer>> m = LabelPropagation.run(graph, signalSteps.get()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final JFreeChart chart = ChartFactory.createStackedBarChart("Evolving Label Propagation", "Signal Step", null, dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); StackedBarRenderer renderer = new StackedBarRenderer(); plot.setDataset(dataset); plot.setRenderer(renderer); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{0} {2} {3}", NumberFormat.getInstance())); renderer.setBaseItemLabelsVisible(true); if (signalSteps.get() > 10) { long stepInterval = Math.round(new Double(signalSteps.get().doubleValue() / 10d)); for (int i = (int) stepInterval; i <= signalSteps.get(); i += stepInterval) { Set<Map.Entry<String, Integer>> entrySet = m.get(new Integer(i)).entrySet(); for (Map.Entry<String, Integer> subentry : entrySet) { dataset.addValue(subentry.getValue(), subentry.getKey(), new Integer(i)); } } } else { for (Map.Entry<Integer, Map<String, Integer>> entry : m.entrySet()) { for (Map.Entry<String, Integer> subentry : entry.getValue().entrySet()) { dataset.addValue(subentry.getValue(), subentry.getKey(), entry.getKey()); } } } renderer.setRenderAsPercentages(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(1200, 600)); ApplicationFrame f = new ApplicationFrame("Label Propagation"); f.setContentPane(chartPanel); f.pack(); f.setVisible(true); }
From source file:de.mpg.escidoc.pubman.statistic_charts.StatisticChartServlet.java
/** * Creates the statistic chart.//from w w w . j av a 2 s . c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset) { // create the chart JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips? false // URLs? ); // set the background color for the chart chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5)); plot.setDomainGridlinePaint(Color.gray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); // set the range axis to display integers only final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); // disable bar outlines... StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); // set up gradient paints for series /* GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); */ Color series1Color = new Color(0xfa, 0x80, 0x72); Color series2Color = new Color(0x64, 0x95, 0xed); renderer.setSeriesPaint(1, series1Color); renderer.setSeriesPaint(0, series2Color); //remove shadow renderer.setShadowVisible(false); // //Labels in bars /* renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(0, Color.white); renderer.setSeriesItemLabelsVisible(1, true); renderer.setSeriesItemLabelGenerator(1, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(1, Color.white); */ //setCategorySummary(dataset); //rotate labels on x-axis CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:de.mpg.mpdl.inge.pubman.web.statistic_charts.StatisticChartServlet.java
/** * Creates the statistic chart./* w w w. j a v a 2 s . com*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset) { // create the chart JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips? false // URLs? ); // set the background color for the chart chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5)); plot.setDomainGridlinePaint(Color.gray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); // set the range axis to display integers only final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); // disable bar outlines... StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); // set up gradient paints for series /* * GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, * 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, * 0, 0)); */ Color series1Color = new Color(0xfa, 0x80, 0x72); Color series2Color = new Color(0x64, 0x95, 0xed); renderer.setSeriesPaint(1, series1Color); renderer.setSeriesPaint(0, series2Color); // remove shadow renderer.setShadowVisible(false); // // Labels in bars /* * renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(0, Color.white); * renderer.setSeriesItemLabelsVisible(1, true); renderer.setSeriesItemLabelGenerator(1, new * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(1, Color.white); */ // setCategorySummary(dataset); // rotate labels on x-axis CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }