List of usage examples for org.jfree.data.category CategoryDataset getRowCount
public int getRowCount();
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset ({@code null} not permitted). * @param base the base value for the bars. * * @return The range ({@code null} if the dataset contains no values). *//*from ww w . ja v a 2s.c o m*/ public static Range findStackedRangeBounds(CategoryDataset dataset, double base) { Args.nullNotPermitted(dataset, "dataset"); Range result = null; double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double positive = base; double negative = base; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { double value = number.doubleValue(); if (value > 0.0) { positive = positive + value; } if (value < 0.0) { negative = negative + value; // '+', remember value is negative } } } minimum = Math.min(minimum, negative); maximum = Math.max(maximum, positive); } if (minimum <= maximum) { result = new Range(minimum, maximum); } return result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>.//from w ww. j av a 2 s. co m * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value (possibly <code>null</code>). */ public static Number findMinimumRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getStartValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { minimum = Math.min(minimum, value.doubleValue()); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Double(minimum); } } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset (<code>null</code> not permitted). * @param base the base value for the bars. * * @return The range (<code>null</code> if the dataset contains no values). *//*from w w w . ja v a2 s . co m*/ public static Range findStackedRangeBounds(CategoryDataset dataset, double base) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result = null; double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double positive = base; double negative = base; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { double value = number.doubleValue(); if (value > 0.0) { positive = positive + value; } if (value < 0.0) { negative = negative + value; // '+', remember value is negative } } } minimum = Math.min(minimum, negative); maximum = Math.max(maximum, positive); } if (minimum <= maximum) { result = new Range(minimum, maximum); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the maximum range value for the specified dataset. This is easy * if the dataset implements the {@link RangeInfo} interface (a good idea * if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * {@code null} if all the data values are {@code null}. * * @param dataset the dataset ({@code null} not permitted). * * @return The maximum value (possibly {@code null}). *//* w w w . ja v a2s . com*/ public static Number findMaximumRangeValue(CategoryDataset dataset) { Args.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeUpperBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getEndValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { maximum = Math.max(maximum, value.doubleValue()); } } } if (maximum == Double.NEGATIVE_INFINITY) { return null; } else { return new Double(maximum); } } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the maximum range value for the specified dataset. This is easy * if the dataset implements the {@link RangeInfo} interface (a good idea * if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values are <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). *//*from w w w .j a va 2 s . c om*/ public static Number findMaximumRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeUpperBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getEndValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { maximum = Math.max(maximum, value.doubleValue()); } } } if (maximum == Double.NEGATIVE_INFINITY) { return null; } else { return new Double(maximum); } } }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.StackedBarChartRenderer.java
/** * //w w w. j a v a 2 s.c o m */ public void createChart() { CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset(); report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true, false); // report.setBackgroundPaint( Color.lightGray ); report.setAntiAlias(false); report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d)); CategoryPlot categoryplot = (CategoryPlot) report.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.lightGray); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); if (datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); } else { numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numberaxis.setLowerMargin(0.0D); StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(); stackedbarrenderer.setDrawBarOutline(false); stackedbarrenderer.setBaseItemLabelsVisible(true); stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD)); int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2) + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10; if (height > ChartUtils.MINIMUM_HEIGHT) { super.setHeight(height); } else { super.setHeight(ChartUtils.MINIMUM_HEIGHT); } Paint[] paints = this.datasetStrategy.getPaintColor(); for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) { stackedbarrenderer.setSeriesPaint(i, paints[i]); } }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.BarChartRenderer.java
public void createChart() { CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset(); report = ChartFactory.createBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true, false);/*from ww w .j a v a 2s . c o m*/ // report.setBackgroundPaint( Color.lightGray ); report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d)); CategoryPlot categoryplot = (CategoryPlot) report.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.lightGray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); if (datasetStrategy instanceof CoberturaBarChartStrategy || datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { numberaxis.setRange(0.0D, BarChartRenderer.NUMBER_AXIS_RANGE); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); } else { numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numberaxis.setLowerMargin(0.0D); CategoryAxis axis = categoryplot.getDomainAxis(); axis.setLowerMargin(0.02); // two percent axis.setCategoryMargin(0.10); // ten percent axis.setUpperMargin(0.02); // two percent BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setItemMargin(0.10); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); if (datasetStrategy instanceof CoberturaBarChartStrategy || datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getPercentInstance(Locale.getDefault()))); } else { barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * categorydataset.getRowCount()); if (height > ChartUtils.MINIMUM_HEIGHT) { super.setHeight(height); } else { super.setHeight(ChartUtils.MINIMUM_HEIGHT); } Paint[] paints = this.datasetStrategy.getPaintColor(); for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) { barrenderer.setSeriesPaint(i, paints[i]); } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBarGroup.java
/** * Inherited by IChart./* w w w . j av a 2s . c om*/ * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); logger.debug("Get plot orientaton"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; } JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // the plot orientation legend, // legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(color); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); int numElForGroup = 0; for (int idx = 0; idx < numGroups.intValue(); idx++) { for (int j = 0; j < numSerieForGroup.intValue(); j++) { try { String tmpSubCat = (String) subCategoryNames.get(j + idx * numSerieForGroup.intValue()); map.mapKeyToGroup(tmpSubCat, "G" + (idx + 1)); } catch (Exception e) { logger.error("out of range error in inserting in stacked bar group: continue anayway", e); } } } renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.0); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); if (percentageValue) renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%"))); else renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; /* MyCategoryUrlGenerator mycatUrl=new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); renderer.setItemURLGenerator(mycatUrl); */ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } int seriesN = dataset.getRowCount(); int numSerieColored = 0; if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { while (numSerieColored < seriesN) { for (int i = 1; i <= colorMap.size(); i++) { Color color = (Color) colorMap.get("SER" + i); Color gradient = new Color(Integer.decode("#FFFFFF").intValue()); if (gradientMap != null) gradient = (Color) gradientMap.get("SER" + i); if (color != null) { Paint p = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, gradient); //renderer.setSeriesPaint(numSerieColored, color); renderer.setSeriesPaint(numSerieColored, p); } numSerieColored++; } } } renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); MyStandardCategoryItemLabelGenerator generator = null; if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); double orient = (-Math.PI / 2.0); if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //vertical labels renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); //horizontal labels /* renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER)); */ } SubCategoryAxis domainAxis = new SubCategoryAxis(categoryLabel + " / " + subCategoryLabel); String subCatLabel = ""; for (int j = 1; j <= numGroups.intValue(); j++) { if (subCatLabelsMap != null) subCatLabel = (String) subCatLabelsMap.get("CAT" + j); else subCatLabel = subCategoryLabel; domainAxis.addSubCategory(subCatLabel); 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()); } plot.setDomainAxis(domainAxis); plot.setRenderer(renderer); /* domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 6.0)); */ if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBar.java
/** * Inherited by IChart.//from w ww .j a va2 s .co m * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); logger.debug("Taken Dataset"); logger.debug("Get plot orientaton"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; } logger.debug("Call Chart Creation"); JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // the plot orientation false, // legend true, // tooltips false // urls ); logger.debug("Chart Created"); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(color); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); logger.debug("set renderer"); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); if (percentageValue) renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%"))); else if (makePercentage) renderer.setRenderAsPercentages(true); /* else renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); */ renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; logger.debug("Calling Url Generation"); MyCategoryUrlGenerator mycatUrl = null; if (rootUrl != null) { logger.debug("Set MycatUrl"); mycatUrl = new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); } if (mycatUrl != null) renderer.setItemURLGenerator(mycatUrl); logger.debug("Text Title"); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } logger.debug("Style Labels"); Color colorSubInvisibleTitle = Color.decode("#FFFFFF"); StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle); TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle); chart.addSubtitle(subsubTitle); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); logger.debug("Axis creation"); // set the range axis to display integers only... NumberFormat nf = NumberFormat.getNumberInstance(locale); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); if (makePercentage) rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); else rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } renderer.setDrawBarOutline(false); logger.debug("Set series color"); int seriesN = dataset.getRowCount(); if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); // if serie has been rinominated I must search with the new name! String nameToSearchWith = (seriesLabelsMap != null && seriesLabelsMap.containsKey(serieName)) ? seriesLabelsMap.get(serieName).toString() : serieName; Color color = (Color) colorMap.get(nameToSearchWith); if (color != null) { renderer.setSeriesPaint(i, color); renderer.setSeriesItemLabelFont(i, new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); } } } logger.debug("If cumulative set series paint " + cumulative); if (cumulative) { int row = dataset.getRowIndex("CUMULATIVE"); if (row != -1) { if (color != null) renderer.setSeriesPaint(row, color); else renderer.setSeriesPaint(row, Color.WHITE); } } MyStandardCategoryItemLabelGenerator generator = null; logger.debug("Are there addition labels " + additionalLabels); logger.debug("Are there value labels " + showValueLabels); if (showValueLabels) { renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); if (valueLabelsPosition.equalsIgnoreCase("inside")) { renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); } else { renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); } } else if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); logger.debug("generator set"); double orient = (-Math.PI / 2.0); logger.debug("add labels style"); if (styleValueLabels.getOrientation() != null && styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); logger.debug("add labels style set"); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //vertical labels renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient)); logger.debug("end of add labels "); } logger.debug("domain axis"); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)); 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()); //opacizzazione colori if (!cumulative) plot.setForegroundAlpha(0.6f); if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.LinkableBar.java
/** * Inherited by IChart.//from ww w . j av a 2s .c o m * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); CategoryAxis categoryAxis = new CategoryAxis(categoryLabel); ValueAxis valueAxis = new NumberAxis(valueLabel); if (rangeIntegerValues == true) { valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } org.jfree.chart.renderer.category.BarRenderer renderer = new org.jfree.chart.renderer.category.BarRenderer(); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); // renderer.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); // renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); if (showValueLabels) { renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); } if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; MyCategoryUrlGenerator mycatUrl = new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); mycatUrl.setDrillDocTitle(drillDocTitle); mycatUrl.setTarget(target); renderer.setItemURLGenerator(mycatUrl); /* } else{ renderer.setItemURLGenerator(new StandardCategoryURLGenerator(rootUrl)); }*/ CategoryPlot plot = new CategoryPlot((CategoryDataset) dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); if (horizontalView) { plot.setOrientation(PlotOrientation.HORIZONTAL); } JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); // get a reference to the plot for further customisation... //CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } // disable bar outlines... //BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); /* if(currentSeries!=null && colorMap!=null){ //for each serie selected int j=0; for (Iterator iterator = currentSeries.iterator(); iterator.hasNext();) { String s = (String) iterator.next(); Integer position=(Integer)seriesNumber.get(s); // check if for that position a value is defined if(colorMap.get("color"+position.toString())!=null){ Color col= (Color)colorMap.get("color"+position); renderer.setSeriesPaint(j, col); } j++; } // close for on series } // close case series selcted and color defined else{ if(colorMap!=null){ // if series not selected check color each one for (Iterator iterator = colorMap.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); Color col= (Color)colorMap.get(key); String keyNum=key.substring(5, key.length()); int num=Integer.valueOf(keyNum).intValue(); num=num-1; renderer.setSeriesPaint(num, col); } } }*/ int seriesN = dataset.getRowCount(); if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); Color color = (Color) colorMap.get(serieName); if (color != null) { renderer.setSeriesPaint(i, color); } } } CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); 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()); if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }