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:RDGraphGenerator.java
/** * Creates a sample chart./* w ww .jav a2 s .c om*/ * * @param dataset the dataset for the chart. * * @return A sample chart. */ private JFreeChart createDistChart(String riderID) { String riderName = (String) riders.get(riderID); final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Distances", // chart title "Month", // domain axis label mainDist, // range axis label (CategoryDataset) riderDistances.get(riderID), // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("0", "G1"); map.mapKeyToGroup("1", "G1"); map.mapKeyToGroup("2", "G1"); map.mapKeyToGroup("3", "G1"); renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.0); Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF)); renderer.setSeriesPaint(0, p1); Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88)); renderer.setSeriesPaint(1, p2); Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f, new Color(0xFF, 0x88, 0x88)); renderer.setSeriesPaint(2, p3); Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f, new Color(0xFF, 0xFF, 0x88)); renderer.setSeriesPaint(3, p4); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(renderer); plot.setFixedLegendItems(createLegendItems()); ValueAxis va = (ValueAxis) plot.getRangeAxis(); ValueAxis ova = null; try { ova = (ValueAxis) va.clone(); } catch (CloneNotSupportedException cnse) { } ova.setLabel(secondaryDist); ova.setLowerBound(va.getLowerBound() * unitConversion); ova.setUpperBound(va.getUpperBound() * unitConversion); plot.setRangeAxis(1, ova); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); CategoryAxis ca = plot.getDomainAxis(); ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); //Make around the chart transparent. chart.setBackgroundPaint(null); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo4.java
protected JFreeChart createLegend(CategoryDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createStackedBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls );/*from www .j a v a 2 s . co m*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("Product 1 (US)", "G1"); map.mapKeyToGroup("Product 1 (Europe)", "G1"); map.mapKeyToGroup("Product 1 (Asia)", "G1"); map.mapKeyToGroup("Product 1 (Middle East)", "G1"); map.mapKeyToGroup("Product 2 (US)", "G2"); map.mapKeyToGroup("Product 2 (Europe)", "G2"); map.mapKeyToGroup("Product 2 (Asia)", "G2"); map.mapKeyToGroup("Product 2 (Middle East)", "G2"); map.mapKeyToGroup("Product 3 (US)", "G3"); map.mapKeyToGroup("Product 3 (Europe)", "G3"); map.mapKeyToGroup("Product 3 (Asia)", "G3"); map.mapKeyToGroup("Product 3 (Middle East)", "G3"); renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.10); renderer.setDrawBarOutline(false); Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF)); renderer.setSeriesPaint(0, p1); renderer.setSeriesPaint(4, p1); renderer.setSeriesPaint(8, p1); Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88)); renderer.setSeriesPaint(1, p2); renderer.setSeriesPaint(5, p2); renderer.setSeriesPaint(9, p2); Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f, new Color(0xFF, 0x88, 0x88)); renderer.setSeriesPaint(2, p3); renderer.setSeriesPaint(6, p3); renderer.setSeriesPaint(10, p3); Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f, new Color(0xFF, 0xFF, 0x88)); renderer.setSeriesPaint(3, p4); renderer.setSeriesPaint(7, p4); renderer.setSeriesPaint(11, p4); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month"); domainAxis.setCategoryMargin(0.05); domainAxis.addSubCategory("Product 1"); domainAxis.addSubCategory("Product 2"); domainAxis.addSubCategory("Product 3"); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(domainAxis); //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); plot.setRenderer(renderer); return chart; }
From source file:edu.uara.wrappers.customcharts.CustomBarChart.java
@Override public void generateStackedBarChart(CategoryDataset dataset) { this.ds = dataset;//store reference to dataset to do update try {//w ww . ja v a 2 s .com if (dataset == null) throw new Exception("No dataset provided"); chart = ChartFactory.createStackedBarChart(title, // chart title domainAxisLabel, // domain axis label rangeAxisLabel, // range axis label dataset, // data orientation, // orientation legend, // include legend false, // no tooltips false // URLs? ); currentDatasetType = DatasetTypes.CategoryDataset; } catch (Exception ex) { System.out.println("Error Generating stacked bar chart :" + ex.getMessage()); } }
From source file:weka.gui.beans.JFreeChartOffscreenChartRenderer.java
/** * Render histogram(s) (numeric attribute) or bar chart (nominal attribute). * Some implementations may not be able to render more than one histogram/bar * on the same chart - the implementation can either throw an exception or * just process the first series in this case. * //from w w w .ja v a 2 s.c om * @param width the width of the resulting chart in pixels * @param height the height of the resulting chart in pixels * @param series a list of Instances - one for each series to be plotted * @param attsToPlot the attribute to plot corresponding to the Instances in * the series list * @param optionalArgs optional arguments to the renderer (may be null) * * @return a BufferedImage containing the chart * @throws Exception if there is a problem rendering the chart */ public BufferedImage renderHistogram(int width, int height, List<Instances> series, String attToPlot, List<String> additionalArgs) throws Exception { String plotTitle = "Bar Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String colorAtt = getOption(additionalArgs, "-color"); String pareto = getOption(additionalArgs, "-pareto"); boolean doPareto = false; if (pareto != null && pareto.length() == 0 && series.size() == 1) { doPareto = true; } if (series.size() == 1 && colorAtt != null && colorAtt.length() > 0) { int colIndex = getIndexOfAttribute(series.get(0), colorAtt); if (colIndex >= 0 && series.get(0).attribute(colIndex).isNominal() && !doPareto) { // split single series out into multiple instances objects - one // per class series = splitToClasses(series.get(0), colIndex); for (Instances insts : series) { insts.setClassIndex(colIndex); } } } Instances masterInstances = series.get(0); int attIndex = getIndexOfAttribute(masterInstances, attToPlot); if (attIndex < 0) { attIndex = 0; } if (!(series.get(0).attribute(attIndex).isNominal() || series.get(0).attribute(attIndex).isRelationValued())) { doPareto = false; } // Do a pareto chart if (doPareto) { final DefaultKeyedValues data = new DefaultKeyedValues(); AttributeStats attStats = masterInstances.attributeStats(attIndex); double[] attValFreqs = attStats.nominalWeights; for (int i = 0; i < attValFreqs.length; i++) { Number freq = new Double(attValFreqs[i]); data.addValue(masterInstances.attribute(attIndex).value(i), freq); } data.sortByValues(SortOrder.DESCENDING); final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); final CategoryDataset dataset = DatasetUtilities .createCategoryDataset(masterInstances.attribute(attIndex).name(), data); final JFreeChart chart = ChartFactory.createBarChart(plotTitle, masterInstances.attribute(attIndex).name(), "Fequency/weight mass", dataset, PlotOrientation.VERTICAL, true, false, false); final CategoryPlot plot = chart.getCategoryPlot(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative); final NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); // plot. plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); chart.setBackgroundPaint(java.awt.Color.white); BufferedImage image = chart.createBufferedImage(width, height); return image; } boolean seriesAreClasses = false; int classIndex = masterInstances.classIndex(); if (classIndex >= 0 && !masterInstances.attribute(classIndex).isNumeric() && !masterInstances.attribute(classIndex).isRelationValued() && masterInstances.attributeStats(classIndex).distinctCount == 1) { // series correspond to class labels (assume that subsequent series only // contain instances of one class)... seriesAreClasses = true; } // bar chart for a nominal attribute if (masterInstances.attribute(attIndex).isNominal() || masterInstances.attribute(attIndex).isString()) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // do the master series String masterSeriesTitle = masterInstances.relationName(); if (seriesAreClasses) { for (int i = 0; i < masterInstances.numInstances(); i++) { Instance current = masterInstances.instance(i); if (!current.isMissing(classIndex)) { masterSeriesTitle = current.stringValue(classIndex); break; } } } AttributeStats attStats = masterInstances.attributeStats(attIndex); double[] attValFreqs = attStats.nominalWeights; for (int i = 0; i < attValFreqs.length; i++) { Number freq = new Double(attValFreqs[i]); dataset.addValue(freq, masterSeriesTitle, masterInstances.attribute(attIndex).value(i)); } // any subsequent series for (int i = 1; i < series.size(); i++) { Instances nextSeries = series.get(i); String seriesTitle = nextSeries.relationName(); if (seriesAreClasses) { for (int j = 0; j < nextSeries.numInstances(); j++) { Instance current = nextSeries.instance(j); if (!current.isMissing(classIndex)) { seriesTitle = current.stringValue(classIndex); break; } } attStats = nextSeries.attributeStats(attIndex); attValFreqs = attStats.nominalWeights; for (int j = 0; j < attValFreqs.length; j++) { Number freq = new Double(attValFreqs[j]); dataset.addValue(freq, seriesTitle, nextSeries.attribute(attIndex).value(j)); } } } JFreeChart chart = null; if (series.size() == 1) { chart = ChartFactory.createBarChart(plotTitle, masterInstances.attribute(attIndex).name(), "Fequency/weight mass", dataset, PlotOrientation.VERTICAL, true, false, false); } else { chart = ChartFactory.createStackedBarChart(plotTitle, masterInstances.attribute(attIndex).name(), "Fequency/weight mass", dataset, PlotOrientation.VERTICAL, true, false, false); } chart.setBackgroundPaint(java.awt.Color.white); BufferedImage image = chart.createBufferedImage(width, height); return image; } else { // histogram for numeric attributes HistogramDataset dataset = new HistogramDataset(); // combine all series in order to get overall std dev, and range Instances temp = new Instances(masterInstances); for (int i = 1; i < series.size(); i++) { Instances additional = series.get(i); for (Instance tempI : additional) { temp.add(tempI); } } AttributeStats stats = temp.attributeStats(attIndex); Stats numericStats = stats.numericStats; double intervalWidth = 3.49 * numericStats.stdDev * StrictMath.pow(temp.numInstances(), (-1.0 / 3.0)); double range = numericStats.max - numericStats.min; int numBins = StrictMath.max(1, (int) StrictMath.round(range / intervalWidth)); // do the master series String masterSeriesTitle = masterInstances.relationName(); if (seriesAreClasses) { for (int i = 0; i < masterInstances.numInstances(); i++) { Instance current = masterInstances.instance(i); if (!current.isMissing(current.classAttribute())) { masterSeriesTitle = current.stringValue(current.classAttribute()); break; } } } // have to set min, max and num bins (using heuristic from AttSummPanel). // Make sure // to set series length to num instances - num missing values for att stats = masterInstances.attributeStats(attIndex); /* * numericStats = stats.numericStats; //numericStats.calculateDerived(); * intervalWidth = StrictMath.max(1, 3.49 * numericStats.stdDev * * StrictMath.pow(masterInstances.numInstances(), (-1.0/3.0))); */ double[] seriesVals = new double[masterInstances.numInstances() - stats.missingCount]; int count = 0; for (int i = 0; i < masterInstances.numInstances(); i++) { Instance current = masterInstances.instance(i); if (!current.isMissing(attIndex)) { seriesVals[count++] = current.value(attIndex); } } dataset.addSeries(masterSeriesTitle, seriesVals, numBins, numericStats.min, numericStats.max); // any subsequent series for (int i = 1; i < series.size(); i++) { Instances nextSeries = series.get(i); String seriesTitle = nextSeries.relationName(); if (seriesAreClasses) { for (int j = 0; j < nextSeries.numInstances(); j++) { Instance current = nextSeries.instance(j); if (!current.isMissing(nextSeries.classAttribute())) { seriesTitle = current.stringValue(nextSeries.classAttribute()); break; } } } stats = nextSeries.attributeStats(attIndex); /* * numericStats = stats.numericStats; // * numericStats.calculateDerived(); intervalWidth = StrictMath.max(1, * 3.49 * numericStats.stdDev * * StrictMath.pow(masterInstances.numInstances(), (-1.0/3.0))); range = * numericStats.max - numericStats.min; numBins = StrictMath.max(1, * (int) StrictMath.round(range / intervalWidth)); */ seriesVals = new double[nextSeries.numInstances() - stats.missingCount]; count = 0; for (int j = 0; j < nextSeries.numInstances(); j++) { Instance current = nextSeries.instance(j); if (!current.isMissing(attIndex)) { seriesVals[count++] = current.value(attIndex); } } dataset.addSeries(seriesTitle, seriesVals, numBins, numericStats.min, numericStats.max); } JFreeChart chart = ChartFactory.createHistogram(plotTitle, masterInstances.attribute(attIndex).name(), null, dataset, PlotOrientation.VERTICAL, true, false, false); // chart.setBackgroundPaint(java.awt.Color.white); XYPlot xyplot = (XYPlot) chart.getPlot(); xyplot.setForegroundAlpha(0.50F); XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer(); xybarrenderer.setDrawBarOutline(false); xybarrenderer.setShadowVisible(false); BufferedImage image = chart.createBufferedImage(width, height); return image; } }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a stacked bar graph representing the total number of tests in * in each build. //w w w . ja va2 s . c o m * * @param builds List of builds * * @return Stacked graph representing automated tests across all builds */ public static final JFreeChart getTestCountChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if ((builds != null) && (builds.size() > 0)) { // Collect build test numbers for each of the builds in the list Collections.sort(builds, new CMnBuildIdComparator()); Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { // Process the test summary for the current build CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); Hashtable testSummary = build.getTestSummary(); if ((testSummary != null) && (testSummary.size() > 0)) { Enumeration keys = testSummary.keys(); while (keys.hasMoreElements()) { String testType = (String) keys.nextElement(); Integer buildId = new Integer(build.getId()); CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType); // Record the total number of tests dataset.addValue(tests.getTotalCount(), testType, buildId); } } } // while list has elements } // if list has elements // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls) chart = ChartFactory.createStackedBarChart("Automated Tests by Type", "Builds", "Test Count", dataset, PlotOrientation.VERTICAL, true, true, false); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); chartFormatter.formatTypeChart(plot, dataset); return chart; }
From source file:spec.reporter.Utils.java
public static void generateMainChart(double compositeScore, TreeMap<String, Double> scores) { // Valid benchmarks + room for all possible extra - compiler, crypto, scimark, scimark.small, scimark.large, startup, xml, composite score Color[] colors = new Color[scores.size() + 8]; // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int count = 0; Iterator<String> iteratorBenchmarks = scores.keySet().iterator(); while (iteratorBenchmarks.hasNext()) { String key = iteratorBenchmarks.next(); Double score = scores.get(key); if (Utils.isValidScore(score)) { dataset.addValue(score, key, key); colors[count++] = (Color) colorMap.get(key); }/*from w ww . j ava 2 s . com*/ } if (Utils.isValidScore(compositeScore)) { dataset.addValue(compositeScore, Utils.CSCORE_NAME, Utils.CSCORE_NAME); colors[count++] = (Color) colorMap.get(Utils.CSCORE_NAME); } JFreeChart chart = ChartFactory.createStackedBarChart("Scores", // chart title "", // domain axis label "", dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend false, // tooltips? false // URLs? ); CategoryItemRenderer renderer = chart.getCategoryPlot().getRendererForDataset(dataset); for (int i = 0; i < count; i++) { Color paint = (Color) colors[i]; if (paint != null) { renderer.setSeriesPaint(i, paint); } } try { ChartUtilities.saveChartAsJPEG(new File(getFullImageName("all")), chart, 600, 50 + (dataset.getRowCount()) * 20); } catch (Exception e) { e.printStackTrace(); } }
From source file:uk.ac.lkl.cram.ui.chart.HoursChartMaker.java
/** * Create a chart from the provided category dataset * @return a Chart that can be rendered in a ChartPanel *///from ww w . ja v a2 s .c o m @Override protected JFreeChart createChart() { //Create a vertical 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.VERTICAL, true, true, false); //Get the font from the platform UI Font chartFont = UIManager.getFont("Label.font"); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Get the renderer from the plot StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer(); //Set the rendered to use a standard bar painter (nothing fancy) sbRenderer.setBarPainter(new StandardBarPainter()); //Set the colours for the bars sbRenderer.setSeriesPaint(0, PREPARATION_COLOR); sbRenderer.setSeriesPaint(1, SUPPORT_COLOR); //Set the tooltip to be series, category and value sbRenderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}, {1} ({2})", NumberFormat.getInstance())); //Get the category axis (that's the X-axis in this case) CategoryAxis categoryAxis = plot.getDomainAxis(); //Set the font for rendering the labels on the x-axis to be the platform default categoryAxis.setLabelFont(chartFont); //Get the number axis (that's the Y-axis in this case) NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); //Use the same font as the x-axis numberAxis.setLabelFont(chartFont); return chart; }
From source file:vis2006.VisGrafik.java
public JFreeChart createChart(Stand st) { // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 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 && st.tr[k].crop == true) anz = anz + st.tr[k].fac; }/*from ww w .ja v a 2s . c o m*/ if (anz > 0) { Integer m = (5 * i) + 2; dataset.addValue(anz * st.size, st.sp[j].spDef.shortName, m.toString()); } } } // JFreeChart chart = ChartFactory.createStackedBarChart(messages.getString("diameterDistributionCT"), // 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.setSeriesPaint(i, new Color(st.sp[i].spDef.colorRed, st.sp[i].spDef.colorGreen, st.sp[i].spDef.colorBlue)); } 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 = 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].crop == true) anz2 = anz2 + st.tr[k].fac; }//from w w w . j av a 2s .co 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 && st.tr[k].crop == true) 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("diameterDistributionCT"), // 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.setSeriesPaint(i, new Color(st.sp[i].spDef.colorRed, st.sp[i].spDef.colorGreen, st.sp[i].spDef.colorBlue)); } return chart; }
From source file:org.tiefaces.components.websheet.chart.ChartHelper.java
/** * Create jfree bar chart.//from ww w. java 2s .c o m * * @param chartData * contain information gathered from excel chart object. * @param vertical * chart orientation. * @return jfree line chart. */ public JFreeChart createStackedBarChart(final ChartData chartData, final boolean vertical) { PlotOrientation orientation = PlotOrientation.VERTICAL; if (!vertical) { orientation = PlotOrientation.HORIZONTAL; } // create the chart... final JFreeChart chart = ChartFactory.createStackedBarChart(chartData.getTitle(), // chart title chartData.getCatAx().getTitle(), // x axis label chartData.getValAx().getTitle(), // y axis label createDataset(chartData), // data orientation, true, // include legend false, // tooltips false // urls ); setupBarStyle(chart, chartData); return chart; }