List of usage examples for org.jfree.chart.renderer.category BarRenderer3D BarRenderer3D
public BarRenderer3D()
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a bar chart with a 3D effect. The chart object returned by this * method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as * the range axis, and a {@link BarRenderer3D} as the renderer. * // ww w. j a va2s . c o m * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> not permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bar chart with a 3D effect. */ public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); BarRenderer3D renderer = new BarRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); if (orientation == PlotOrientation.HORIZONTAL) { // change rendering order to ensure that bar overlapping is the // right way around plot.setRowRenderingOrder(SortOrder.DESCENDING); plot.setColumnRenderingOrder(SortOrder.DESCENDING); } plot.setForegroundAlpha(0.75f); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createBarChart(final CategoryDatasetChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); PlotOrientation orientation = chartDefinition.getOrientation(); CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = null;/*from w w w . jav a 2 s .c o m*/ // Determine the type of renderer to use if (chartDefinition.isStacked() || chartDefinition.isThreeD()) { if (chartDefinition.isStacked() && chartDefinition.isThreeD()) { renderer = new StackedBarRenderer3D(); } else if (chartDefinition.isStacked()) { renderer = new StackedBarRenderer(); } else { renderer = new BarRenderer3D(); } } else { renderer = new BarRenderer(); } if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setNegativeItemLabelPosition(position2); } if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } if (chartDefinition.getMaxBarWidth() != null) { renderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue()); } CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer); JFreeChartEngine.updatePlot(plot, chartDefinition); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a bar chart with a 3D effect. The chart object returned by this * method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as * the range axis, and a {@link BarRenderer3D} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted)./* w ww. java 2 s. com*/ * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> not permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bar chart with a 3D effect. */ public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); BarRenderer3D renderer = new BarRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); if (orientation == PlotOrientation.HORIZONTAL) { // change rendering order to ensure that bar overlapping is the // right way around plot.setRowRenderingOrder(SortOrder.DESCENDING); plot.setColumnRenderingOrder(SortOrder.DESCENDING); } plot.setForegroundAlpha(0.75f); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; String secondValueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); PlotOrientation orientation = chartDefinition.getOrientation(); // split BarLineChartDefinition in two Definitions CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); /*//from ww w .j av a2 s . co m * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset = * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){} */ // get column and row count of the data set int iColumnCount = chartDefinition.getColumnCount(); int iRowCount = chartDefinition.getRowCount(); if (iRowCount <= 0) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE")); //$NON-NLS-1$ } /* * Copy data to the two new data sets */ // Loop through columns for (int r = 0; r < iRowCount; r++) { // check if measure should be include in bar or line dataset String strMeasureName = (String) chartDefinition.getRowKey(r); boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName); boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName); // getting all values for (int c = 0; c < iColumnCount; c++) { Comparable compColumnName = chartDefinition.getColumnKey(c); Number nValue = chartDefinition.getValue(strMeasureName, compColumnName); if (bIsBarColumn) { barsDataset.addValue(nValue, strMeasureName, compColumnName); } if (bIsLineColumn) { linesDataset.addValue(nValue, strMeasureName, compColumnName); } } } if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT")); //$NON-NLS-1$ } // Create Axis Objects CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel); NumberAxis barsAxis = new NumberAxis(valueAxisLabel); NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel); // set title and font for lines Axis linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle()); linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont()); if (chartDefinition.getLinesRangeTickFormat() != null) { linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat()); } // create renderer BarRenderer barRenderer = null; LineAndShapeRenderer lineRenderer = null; // Determine the type of renderer to use if (chartDefinition.isStacked() || chartDefinition.isThreeD()) { if (chartDefinition.isStacked() && chartDefinition.isThreeD()) { barRenderer = new StackedBarRenderer3D(); lineRenderer = new LineRenderer3D(); } else if (chartDefinition.isStacked()) { barRenderer = new StackedBarRenderer(); lineRenderer = new LineAndShapeRenderer(); } else { barRenderer = new BarRenderer3D(); lineRenderer = new LineRenderer3D(); } } else { barRenderer = new BarRenderer(); lineRenderer = new LineAndShapeRenderer(); } if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } if (tooltips) { barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } if (chartDefinition.getMaxBarWidth() != null) { barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue()); } // setting some line attributes lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible()); lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible()); /* * Create plot and make necessary adjustments for overlaid chart */ // create the plot with bar chart CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer); // add line renderer plot.setRenderer(1, lineRenderer); // add lines dataset, renderer and axis to plot plot.setDataset(1, linesDataset); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // standard settings for plots JFreeChartEngine.updatePlot(plot, barsDataset); // additional settings for second axis ValueAxis secondValueAxis = plot.getRangeAxis(1); if (secondValueAxis != null) { if (chartDefinition.getLinesRangeTitle() != null) { secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle()); } if (chartDefinition.getLinesRangeTitleFont() != null) { secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont()); } if (chartDefinition.getLinesRangeTickFont() != null) { secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont()); } if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum()); } if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum()); } } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }