List of usage examples for org.jfree.chart.plot CombinedDomainCategoryPlot CombinedDomainCategoryPlot
public CombinedDomainCategoryPlot()
From source file:com.bdb.weather.display.summary.TemperatureBinSummaryPlot.java
public TemperatureBinSummaryPlot() { plot = new CombinedDomainCategoryPlot(); JFreeChart chart = new JFreeChart(plot); setMaxHeight(10000);// w ww. j a v a2 s .c om setMaxWidth(10000); NumberAxis countAxis = new NumberAxis("Day Count"); countAxis.setUpperMargin(.2); countPlot.setRangeAxis(countAxis); countPlot.setDataset(countDataset); BarRenderer r = new BarRenderer(); r.setBaseItemLabelsVisible(true); r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); r.setSeriesPaint(0, Color.BLUE); r.setBasePaint(Color.BLUE); countPlot.setRenderer(r); NumberAxis durationAxis = new NumberAxis("Duration (Hours)"); durationAxis.setUpperMargin(.2); durationPlot.setRangeAxis(durationAxis); durationPlot.setDataset(durationDataset); r = new BarRenderer(); r.setBaseItemLabelsVisible(true); NumberFormat format = DecimalFormat.getNumberInstance(); format.setMaximumFractionDigits(1); format.setMinimumFractionDigits(1); r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, format)); r.setSeriesPaint(0, Color.RED); r.setBasePaint(Color.RED); durationPlot.setRenderer(r); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); plot.add(countPlot); plot.add(durationPlot); chartViewer = new ChartViewer(chart); this.setCenter(chartViewer); }
From source file:org.matsim.counts.algorithms.graphs.BoxPlotErrorGraph.java
@SuppressWarnings("unchecked") @Override// www . jav a 2 s .com public JFreeChart createChart(final int nbr) { DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset(); DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset(); final ArrayList<Double>[] listRel = new ArrayList[24]; final ArrayList<Double>[] listAbs = new ArrayList[24]; // init for (int i = 0; i < 24; i++) { listRel[i] = new ArrayList<Double>(); listAbs[i] = new ArrayList<Double>(); } // add the values of all counting stations to each hour for (CountSimComparison cc : this.ccl_) { int hour = cc.getHour() - 1; listRel[hour].add(cc.calculateRelativeError()); listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue()); } // add the collected values to the graph / dataset for (int i = 0; i < 24; i++) { dataset0.add(listRel[i], "Rel Error", Integer.toString(i + 1)); dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1)); } String title = "Iteration: " + this.iteration_; final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); final CategoryAxis xAxis = new CategoryAxis("Hour"); final NumberAxis yAxis0 = new NumberAxis("Signed Rel. Error [%]"); final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]"); yAxis0.setAutoRangeIncludesZero(false); yAxis1.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator()); CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer); CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer); plot.add(subplot0); plot.add(subplot1); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.setDomainAxis(axis1); this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false); return this.chart_; }
From source file:org.matsim.counts.algorithms.graphs.BoxPlotNormalizedErrorGraph.java
@SuppressWarnings("unchecked") @Override/*from w ww. j ava 2s . c o m*/ public JFreeChart createChart(final int nbr) { DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset(); DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset(); final ArrayList<Double>[] listRel = new ArrayList[24]; final ArrayList<Double>[] listAbs = new ArrayList[24]; // init for (int i = 0; i < 24; i++) { listRel[i] = new ArrayList<Double>(); listAbs[i] = new ArrayList<Double>(); } // add the values of all counting stations to each hour for (CountSimComparison cc : this.ccl_) { int hour = cc.getHour() - 1; listRel[hour].add(cc.calculateNormalizedRelativeError() * 100); listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue()); } // add the collected values to the graph / dataset for (int i = 0; i < 24; i++) { dataset0.add(listRel[i], "Rel Norm Error", Integer.toString(i + 1)); dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1)); } String title = "Iteration: " + this.iteration_; final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); final CategoryAxis xAxis = new CategoryAxis("Hour"); final NumberAxis yAxis0 = new NumberAxis("Norm. Rel. Error [%]"); final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]"); yAxis0.setAutoRangeIncludesZero(false); yAxis1.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator()); CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer); CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer); plot.add(subplot0); plot.add(subplot1); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.setDomainAxis(axis1); this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false); return this.chart_; }
From source file:com.sun.japex.ChartGenerator.java
private JFreeChart generateDriverBarChart() { try {/*w w w. java 2s . co m*/ String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X); // Ensure japex.resultUnitX is not null if (resultUnitX == null) { resultUnitX = ""; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset datasetX = new DefaultCategoryDataset(); // Find first normalizer driver (if any) and adjust unit DriverImpl normalizerDriver = null; for (DriverImpl driver : _testSuite.getDriverInfoList()) { if (driver.isNormal()) { normalizerDriver = driver; break; } } // Check if normalizer driver can be used as such if (normalizerDriver != null) { if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) { System.out.println("Warning: Driver '" + normalizerDriver.getName() + "' cannot be used to normalize results"); normalizerDriver = null; } else { resultUnit = "% of " + resultUnit; if (resultUnitX != null) { resultUnitX = "% of " + resultUnitX; } } } boolean hasValueX = false; // Generate charts for (DriverImpl di : _testSuite.getDriverInfoList()) { if (normalizerDriver != null) { dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)), di.getName(), "Arithmetic Mean"); dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)), di.getName(), "Geometric Mean"); dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)), di.getName(), "Harmonic Mean"); if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) { datasetX.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X) / normalizerDriver .getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X)), di.getName(), "Arithmetic Mean"); datasetX.addValue( normalizerDriver == di ? 100.0 : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X) / normalizerDriver .getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X)), di.getName(), "Geometric Mean"); datasetX.addValue( (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X) / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X)), di.getName(), "Harmonic Mean"); hasValueX = true; } } else { dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN), di.getName(), "Arithmetic Mean"); dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN), di.getName(), "Geometric Mean"); dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN), di.getName(), "Harmonic Mean"); if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) { datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X), di.getName(), "Arithmetic Mean"); datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X), di.getName(), "Geometric Mean"); datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X), di.getName(), "Harmonic Mean"); hasValueX = true; } } } int nextPlotIndex = 1; CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); // Use same renderer in combine charts to get same colors BarRenderer3D renderer = new BarRenderer3D(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); // Bar chart for secondary data set based on japex.resultValueX if (hasValueX) { NumberAxis rangeAxisX = new NumberAxis(resultUnitX); CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer); // Set transparency and clear legend for this plot subplotX.setForegroundAlpha(0.7f); subplotX.setFixedLegendItems(new LegendItemCollection()); plot.add(subplotX, nextPlotIndex++); _chartHeight += 50; // Adjust chart height } else { } // Bar chart for main data set based on japex.resultValue NumberAxis rangeAxis = new NumberAxis(resultUnit); CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer); subplot.setForegroundAlpha(0.7f); // transparency plot.add(subplot, nextPlotIndex); // Create chart and save it as JPEG String chartTitle = "Result Summary"; JFreeChart chart = new JFreeChart(hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"), new Font("SansSerif", Font.BOLD, 14), plot, true); chart.setAntiAlias(true); return chart; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.CombinedCategoryBar.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); // recover the datasets DefaultCategoryDataset datasetBarFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-bar"); DefaultCategoryDataset datasetBarSecondAxis = (DefaultCategoryDataset) datasets.getDatasets().get("2-bar"); DefaultCategoryDataset datasetLineFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-line"); DefaultCategoryDataset datasetLineSecondAxis = (DefaultCategoryDataset) datasets.getDatasets() .get("2-line"); // create the two subplots CategoryPlot subPlot1 = new CategoryPlot(); CategoryPlot subPlot2 = new CategoryPlot(); CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); subPlot1.setDataset(0, datasetBarFirstAxis); subPlot2.setDataset(0, datasetBarSecondAxis); subPlot1.setDataset(1, datasetLineFirstAxis); subPlot2.setDataset(1, datasetLineSecondAxis); // localize numbers on y axis NumberFormat nf = (NumberFormat) NumberFormat.getNumberInstance(locale); // Range Axis 1 NumberAxis rangeAxis = new NumberAxis(getValueLabel()); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis/*from w w w . j a va 2 s .com*/ .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setUpperMargin(0.10); rangeAxis.setNumberFormatOverride(nf); subPlot1.setRangeAxis(rangeAxis); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // Range Axis 2 NumberAxis rangeAxis2 = new NumberAxis(secondAxisLabel); rangeAxis2.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis2.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis2 .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis2.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis2.setUpperMargin(0.10); rangeAxis2.setNumberFormatOverride(nf); subPlot2.setRangeAxis(rangeAxis2); if (rangeIntegerValues == true) { rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // Category Axis CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel()); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); domainAxis.setUpperMargin(0.10); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); // Add subplots to main plot plot.add(subPlot1, 1); plot.add(subPlot2, 2); MyStandardCategoryItemLabelGenerator generator = null; // value labels and additional values are mutually exclusive if (showValueLabels == true) additionalLabels = false; if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); } // Create Renderers! CategoryItemRenderer barRenderer1 = new BarRenderer(); CategoryItemRenderer barRenderer2 = new BarRenderer(); LineAndShapeRenderer lineRenderer1 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null; LineAndShapeRenderer lineRenderer2 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null; subPlot1.setRenderer(0, barRenderer1); subPlot2.setRenderer(0, barRenderer2); if (useLinesRenderers == true) { subPlot1.setRenderer(1, lineRenderer1); subPlot2.setRenderer(1, lineRenderer2); // no shapes for line_no_shapes series for (Iterator iterator = lineNoShapeSeries1.iterator(); iterator.hasNext();) { String ser = (String) iterator.next(); // if there iS a abel associated search for that String label = null; if (seriesLabelsMap != null) { label = (String) seriesLabelsMap.get(ser); } if (label == null) label = ser; int index = datasetLineFirstAxis.getRowIndex(label); if (index != -1) { lineRenderer1.setSeriesShapesVisible(index, false); } } for (Iterator iterator = lineNoShapeSeries2.iterator(); iterator.hasNext();) { String ser = (String) iterator.next(); // if there iS a abel associated search for that String label = null; if (seriesLabelsMap != null) { label = (String) seriesLabelsMap.get(ser); } if (label == null) label = ser; int index = datasetLineSecondAxis.getRowIndex(label); if (index != -1) { lineRenderer2.setSeriesShapesVisible(index, false); } } } // add tooltip if enabled if (enableToolTips) { MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips, seriesTooltip, categoriesTooltip, seriesCaptions); barRenderer1.setToolTipGenerator(generatorToolTip); barRenderer2.setToolTipGenerator(generatorToolTip); if (useLinesRenderers) { lineRenderer1.setToolTipGenerator(generatorToolTip); lineRenderer2.setToolTipGenerator(generatorToolTip); } } subPlot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); subPlot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // COnfigure renderers: I do in extensive way so will be easier to add customization in the future if (maxBarWidth != null) { ((BarRenderer) barRenderer1).setMaximumBarWidth(maxBarWidth.doubleValue()); ((BarRenderer) barRenderer2).setMaximumBarWidth(maxBarWidth.doubleValue()); } // Values or addition Labels for first BAR Renderer if (showValueLabels) { barRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); barRenderer1.setBaseItemLabelsVisible(true); barRenderer1.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); barRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor()); barRenderer1.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); barRenderer1.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); barRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); barRenderer2.setBaseItemLabelsVisible(true); barRenderer2.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); barRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor()); barRenderer2.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); barRenderer2.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); } else if (additionalLabels) { barRenderer1.setBaseItemLabelGenerator(generator); barRenderer2.setBaseItemLabelGenerator(generator); double orient = (-Math.PI / 2.0); if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } barRenderer1.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); barRenderer1.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); barRenderer2.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); barRenderer2.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); } // Values or addition Labels for line Renderers if requested if (useLinesRenderers == true) { if (showValueLabels) { lineRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); lineRenderer1.setBaseItemLabelsVisible(true); lineRenderer1.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); lineRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor()); lineRenderer1.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); lineRenderer1.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); lineRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); lineRenderer2.setBaseItemLabelsVisible(true); lineRenderer2.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); lineRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor()); lineRenderer2.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); lineRenderer2.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); } else if (additionalLabels) { lineRenderer1.setBaseItemLabelGenerator(generator); lineRenderer2.setBaseItemLabelGenerator(generator); double orient = (-Math.PI / 2.0); if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } lineRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); lineRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); lineRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); lineRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); } } // Bar Dataset Colors! if (colorMap != null) { int idx = -1; for (Iterator iterator = datasetBarFirstAxis.getRowKeys().iterator(); iterator.hasNext();) { idx++; String serName = (String) iterator.next(); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serName; serName = (String) seriesCaptions.get(serName); index = datasetBarFirstAxis.getRowIndex(labelName); } else index = datasetBarFirstAxis.getRowIndex(serName); Color color = (Color) colorMap.get(serName); if (color != null) { barRenderer1.setSeriesPaint(index, color); } } for (Iterator iterator = datasetBarSecondAxis.getRowKeys().iterator(); iterator.hasNext();) { idx++; String serName = (String) iterator.next(); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serName; serName = (String) seriesCaptions.get(serName); index = datasetBarSecondAxis.getRowIndex(labelName); } else index = datasetBarSecondAxis.getRowIndex(serName); Color color = (Color) colorMap.get(serName); if (color != null) { barRenderer2.setSeriesPaint(index, color); } } } // LINE Dataset Colors! if (useLinesRenderers == true) { if (colorMap != null) { int idx = -1; for (Iterator iterator = datasetLineFirstAxis.getRowKeys().iterator(); iterator.hasNext();) { idx++; String serName = (String) iterator.next(); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serName; serName = (String) seriesCaptions.get(serName); index = datasetLineFirstAxis.getRowIndex(labelName); } else index = datasetLineFirstAxis.getRowIndex(serName); Color color = (Color) colorMap.get(serName); if (color != null) { lineRenderer1.setSeriesPaint(index, color); } } for (Iterator iterator = datasetLineSecondAxis.getRowKeys().iterator(); iterator.hasNext();) { idx++; String serName = (String) iterator.next(); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serName; serName = (String) seriesCaptions.get(serName); index = datasetLineSecondAxis.getRowIndex(labelName); } else index = datasetLineSecondAxis.getRowIndex(serName); Color color = (Color) colorMap.get(serName); if (color != null) { lineRenderer2.setSeriesPaint(index, color); } } } } //defines url for drill boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; logger.debug("Calling Url Generation"); MyCategoryUrlGenerator mycatUrl = null; if (super.rootUrl != null) { logger.debug("Set MycatUrl"); mycatUrl = new MyCategoryUrlGenerator(super.rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(super.categoryUrlName); mycatUrl.setSerieUrlLabel(super.serieUrlname); mycatUrl.setDrillDocTitle(drillDocTitle); mycatUrl.setTarget(target); } if (mycatUrl != null) { barRenderer1.setItemURLGenerator(mycatUrl); barRenderer2.setItemURLGenerator(mycatUrl); if (useLinesRenderers) { lineRenderer1.setItemURLGenerator(mycatUrl); lineRenderer2.setItemURLGenerator(mycatUrl); } } plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.setBackgroundPaint(Color.white); // I want to re order the legend LegendItemCollection legends = plot.getLegendItems(); // legend Temp HashMap<String, LegendItem> legendTemp = new HashMap<String, LegendItem>(); Vector<String> alreadyInserted = new Vector<String>(); for (int i = 0; i < legends.getItemCount(); i++) { LegendItem item = legends.get(i); String label = item.getLabel(); legendTemp.put(label, item); } LegendItemCollection newLegend = new LegendItemCollection(); // force the order of the ones specified for (Iterator iterator = seriesOrder.iterator(); iterator.hasNext();) { String serie = (String) iterator.next(); if (legendTemp.keySet().contains(serie)) { newLegend.add(legendTemp.get(serie)); alreadyInserted.add(serie); } } // check that there are no serie not specified, otherwise add them for (Iterator iterator = legendTemp.keySet().iterator(); iterator.hasNext();) { String serie = (String) iterator.next(); if (!alreadyInserted.contains(serie)) { newLegend.add(legendTemp.get(serie)); } } plot.setFixedLegendItems(newLegend); if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }
From source file:com.sun.japex.ChartGenerator.java
private int generateTestCaseBarCharts(String baseName, String extension) { int nOfFiles = 0; List<DriverImpl> driverInfoList = _testSuite.getDriverInfoList(); // Get number of tests from first driver final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size(); int groupSizesIndex = 0; int[] groupSizes = calculateGroupSizes(nOfTests, _plotGroupSize); try {/* w w w. j a v a2 s . c o m*/ String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X); // Ensure japex.resultUnitX is not null if (resultUnitX == null) { resultUnitX = ""; } // Find first normalizer driver (if any) DriverImpl normalizerDriver = null; for (DriverImpl di : driverInfoList) { if (di.isNormal()) { normalizerDriver = di; break; } } // Check if normalizer driver can be used as such if (normalizerDriver != null) { if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0 || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) { normalizerDriver = null; } else { resultUnit = "% of " + resultUnit; if (resultUnitX != null) { resultUnitX = "% of " + resultUnitX; } } } // Generate charts DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset datasetX = new DefaultCategoryDataset(); boolean hasValueX = false; int i = 0, thisGroupSize = 0; for (; i < nOfTests; i++) { for (DriverImpl di : driverInfoList) { TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(i); // User normalizer driver if defined if (normalizerDriver != null) { TestCaseImpl normalTc = (TestCaseImpl) normalizerDriver.getAggregateTestCases().get(i); dataset.addValue( normalizerDriver == di ? 100.0 : (100.0 * tc.getDoubleParamNoNaN(Constants.RESULT_VALUE) / normalTc.getDoubleParamNoNaN(Constants.RESULT_VALUE)), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); if (tc.hasParam(Constants.RESULT_VALUE_X)) { datasetX.addValue( (100.0 * tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X) / normalTc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X)), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); hasValueX = true; } } else { dataset.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); if (tc.hasParam(Constants.RESULT_VALUE_X)) { datasetX.addValue(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X), _plotDrivers ? tc.getName() : di.getName(), _plotDrivers ? di.getName() : tc.getName()); hasValueX = true; } } } thisGroupSize++; // Generate chart for this group if complete if (thisGroupSize == groupSizes[groupSizesIndex]) { int nextPlotIndex = 1; CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(); // Use same renderer in combine charts to get same colors BarRenderer3D renderer = new BarRenderer3D(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); // Bar chart for secondary data set based on japex.resultValueX if (hasValueX) { NumberAxis rangeAxisX = new NumberAxis(resultUnitX); CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer); // Set transparency and clear legend for this plot subplotX.setForegroundAlpha(0.7f); subplotX.setFixedLegendItems(new LegendItemCollection()); plot.add(subplotX, nextPlotIndex++); _chartHeight += 50; // Adjust chart height } // Bar chart for main data set based on japex.resultValue NumberAxis rangeAxis = new NumberAxis(resultUnit); CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer); subplot.setForegroundAlpha(0.7f); // transparency plot.add(subplot, nextPlotIndex); // Create chart and save it as JPEG String chartTitle = _plotDrivers ? "Results per Driver" : "Results per Test"; JFreeChart chart = new JFreeChart( hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"), new Font("SansSerif", Font.BOLD, 14), plot, true); chart.setAntiAlias(true); ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension), chart, _chartWidth, _chartHeight); nOfFiles++; groupSizesIndex++; thisGroupSize = 0; // Create fresh data sets dataset = new DefaultCategoryDataset(); datasetX = new DefaultCategoryDataset(); } } } catch (RuntimeException e) { throw e; } catch (Exception e) { e.printStackTrace(); } return nOfFiles; }