List of usage examples for org.jfree.chart.labels ItemLabelAnchor OUTSIDE9
ItemLabelAnchor OUTSIDE9
To view the source code for org.jfree.chart.labels ItemLabelAnchor OUTSIDE9.
Click Source Link
From source file:com.googlecode.logVisualizer.chart.HorizontalIntervallBarChartBuilder.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final CategoryAxis categoryAxis = plot.getDomainAxis(); final LayeredBarRenderer renderer = new LayeredBarRenderer(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.black); setBarShadowVisible(chart, false);/*from w w w.j av a 2 s. c om*/ plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRangeAxis().setLowerBound(-35); plot.getRangeAxis().setUpperBound(35); renderer.setDrawBarOutline(false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.green); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER)); renderer.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.CENTER)); renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER)); renderer.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER)); renderer.setItemLabelAnchorOffset(9.0); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); categoryAxis.setCategoryMargin(0.15); categoryAxis.setUpperMargin(0.0175); categoryAxis.setLowerMargin(0.0175); return chart; }
From source file:org.openfaces.component.chart.impl.plots.PlotUtil.java
private static void defaultInit(PlotOrientation orientation, AbstractRenderer renderer) { 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); }/*from w w w. ja v a 2s . com*/ }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createBarChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setBaseNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); }// w w w .j ava2 s . c o m if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Bar Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setDrawBarOutline(false); GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); categoryAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java
private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar, PlotOrientation orientation) {/* www . j av a2s . c om*/ Point2D result = null; double offset = getItemLabelAnchorOffset(); double x0 = bar.getX() - offset; double x1 = bar.getX(); double x2 = bar.getX() + offset; double x3 = bar.getCenterX(); double x4 = bar.getMaxX() - offset; double x5 = bar.getMaxX(); double x6 = bar.getMaxX() + offset; double y0 = bar.getMaxY() + offset; double y1 = bar.getMaxY(); double y2 = bar.getMaxY() - offset; double y3 = bar.getCenterY(); double y4 = bar.getMinY() + offset; double y5 = bar.getMinY(); double y6 = bar.getMinY() - offset; if (anchor == ItemLabelAnchor.CENTER) { result = new Point2D.Double(x3, y3); } else if (anchor == ItemLabelAnchor.INSIDE1) { result = new Point2D.Double(x4, y4); } else if (anchor == ItemLabelAnchor.INSIDE2) { result = new Point2D.Double(x4, y4); } else if (anchor == ItemLabelAnchor.INSIDE3) { result = new Point2D.Double(x4, y3); } else if (anchor == ItemLabelAnchor.INSIDE4) { result = new Point2D.Double(x4, y2); } else if (anchor == ItemLabelAnchor.INSIDE5) { result = new Point2D.Double(x4, y2); } else if (anchor == ItemLabelAnchor.INSIDE6) { result = new Point2D.Double(x3, y2); } else if (anchor == ItemLabelAnchor.INSIDE7) { result = new Point2D.Double(x2, y2); } else if (anchor == ItemLabelAnchor.INSIDE8) { result = new Point2D.Double(x2, y2); } else if (anchor == ItemLabelAnchor.INSIDE9) { result = new Point2D.Double(x2, y3); } else if (anchor == ItemLabelAnchor.INSIDE10) { result = new Point2D.Double(x2, y4); } else if (anchor == ItemLabelAnchor.INSIDE11) { result = new Point2D.Double(x2, y4); } else if (anchor == ItemLabelAnchor.INSIDE12) { result = new Point2D.Double(x3, y4); } else if (anchor == ItemLabelAnchor.OUTSIDE1) { result = new Point2D.Double(x5, y6); } else if (anchor == ItemLabelAnchor.OUTSIDE2) { result = new Point2D.Double(x6, y5); } else if (anchor == ItemLabelAnchor.OUTSIDE3) { result = new Point2D.Double(x6, y3); } else if (anchor == ItemLabelAnchor.OUTSIDE4) { result = new Point2D.Double(x6, y1); } else if (anchor == ItemLabelAnchor.OUTSIDE5) { result = new Point2D.Double(x5, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE6) { result = new Point2D.Double(x3, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE7) { result = new Point2D.Double(x1, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE8) { result = new Point2D.Double(x0, y1); } else if (anchor == ItemLabelAnchor.OUTSIDE9) { result = new Point2D.Double(x0, y3); } else if (anchor == ItemLabelAnchor.OUTSIDE10) { result = new Point2D.Double(x0, y5); } else if (anchor == ItemLabelAnchor.OUTSIDE11) { result = new Point2D.Double(x1, y6); } else if (anchor == ItemLabelAnchor.OUTSIDE12) { result = new Point2D.Double(x3, y6); } return result; }
From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java
/** * Calculates the item label anchor point. * * @param anchor the anchor.//w ww. java2s.com * @param x the x coordinate. * @param y the y coordinate. * @param orientation the plot orientation. * @return The anchor point (never <code>null</code>). */ @Override protected Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, double x, double y, PlotOrientation orientation) { Point2D result = null; double sizeX = 2.0 * this.itemLabelAnchorOffset; double sizeY = 2.0 * this.itemLabelAnchorOffset; if (currCircle != null) { sizeX = currCircle.getWidth() / 2.0 + this.itemLabelAnchorOffset; sizeY = currCircle.getHeight() / 2.0 + this.itemLabelAnchorOffset; } if (anchor == ItemLabelAnchor.CENTER) { result = new Point2D.Double(x, y); } else if (anchor == ItemLabelAnchor.INSIDE1) { result = new Point2D.Double(x + OPP * this.itemLabelAnchorOffset, y - ADJ * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE2) { result = new Point2D.Double(x + ADJ * this.itemLabelAnchorOffset, y - OPP * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE3) { result = new Point2D.Double(x + this.itemLabelAnchorOffset, y); } else if (anchor == ItemLabelAnchor.INSIDE4) { result = new Point2D.Double(x + ADJ * this.itemLabelAnchorOffset, y + OPP * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE5) { result = new Point2D.Double(x + OPP * this.itemLabelAnchorOffset, y + ADJ * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE6) { result = new Point2D.Double(x, y + this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE7) { result = new Point2D.Double(x - OPP * this.itemLabelAnchorOffset, y + ADJ * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE8) { result = new Point2D.Double(x - ADJ * this.itemLabelAnchorOffset, y + OPP * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE9) { result = new Point2D.Double(x - this.itemLabelAnchorOffset, y); } else if (anchor == ItemLabelAnchor.INSIDE10) { result = new Point2D.Double(x - ADJ * this.itemLabelAnchorOffset, y - OPP * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE11) { result = new Point2D.Double(x - OPP * this.itemLabelAnchorOffset, y - ADJ * this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.INSIDE12) { result = new Point2D.Double(x, y - this.itemLabelAnchorOffset); } else if (anchor == ItemLabelAnchor.OUTSIDE1) { result = new Point2D.Double(x + sizeX * OPP, y - sizeY * ADJ); } else if (anchor == ItemLabelAnchor.OUTSIDE2) { result = new Point2D.Double(x + sizeX * ADJ, y - sizeY * OPP); } else if (anchor == ItemLabelAnchor.OUTSIDE3) { result = new Point2D.Double(x + sizeX, y); } else if (anchor == ItemLabelAnchor.OUTSIDE4) { result = new Point2D.Double(x + sizeX * ADJ, y + sizeY * OPP); } else if (anchor == ItemLabelAnchor.OUTSIDE5) { result = new Point2D.Double(x + sizeX * OPP, y + sizeY * ADJ); } else if (anchor == ItemLabelAnchor.OUTSIDE6) { result = new Point2D.Double(x, y + sizeY); } else if (anchor == ItemLabelAnchor.OUTSIDE7) { result = new Point2D.Double(x - sizeX * OPP, y + sizeY * ADJ); } else if (anchor == ItemLabelAnchor.OUTSIDE8) { result = new Point2D.Double(x - sizeX * ADJ, y + sizeY * OPP); } else if (anchor == ItemLabelAnchor.OUTSIDE9) { result = new Point2D.Double(x - sizeX, y); } else if (anchor == ItemLabelAnchor.OUTSIDE10) { result = new Point2D.Double(x - sizeX * ADJ, y - sizeY * OPP); } else if (anchor == ItemLabelAnchor.OUTSIDE11) { result = new Point2D.Double(x - sizeX * OPP, y - sizeY * ADJ); } else if (anchor == ItemLabelAnchor.OUTSIDE12) { result = new Point2D.Double(x, y - sizeY); } return result; }
From source file:org.leo.benchmark.Benchmark.java
/** * Create a chartpanel//from w w w . ja v a 2s . co m * * @param title title * @param dataName name of the data * @param clazzResult data mapped by classes * @param catItemLabelGenerator label generator * @return the chartPanel */ @SuppressWarnings("serial") private ChartPanel createChart(String title, String dataName, Map<Class<? extends Collection<?>>, Long> clazzResult, AbstractCategoryItemLabelGenerator catItemLabelGenerator) { // sort data by class name List<Class<? extends Collection<?>>> clazzes = new ArrayList<Class<? extends Collection<?>>>( clazzResult.keySet()); Collections.sort(clazzes, new Comparator<Class<? extends Collection<?>>>() { @Override public int compare(Class<? extends Collection<?>> o1, Class<? extends Collection<?>> o2) { return o1.getCanonicalName().compareTo(o2.getCanonicalName()); } }); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); // add the data to the dataset for (Class<? extends Collection<?>> clazz : clazzes) { dataSet.addValue(clazzResult.get(clazz), clazz.getName(), title.split(" ")[0]); } // create the chart JFreeChart chart = ChartFactory.createBarChart3D(null, null, dataName, dataSet, PlotOrientation.HORIZONTAL, false, true, false); chart.addSubtitle(new TextTitle(title)); // some customization in the style CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(250, 250, 250)); plot.setDomainGridlinePaint(new Color(255, 200, 200)); plot.setRangeGridlinePaint(Color.BLUE); plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setLabelFont(new Font("arial", Font.PLAIN, 10)); BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); // display the class name in the bar chart for (int i = 0; i < clazzResult.size(); i++) { renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator() { @Override public String generateLabel(CategoryDataset dataset, int row, int column) { String label = " " + dataset.getRowKey(row).toString(); if (dataset.getValue(row, column).equals(timeout * 1000000)) { label += " (Timeout)"; } return label; } }); renderer.setSeriesItemLabelsVisible(i, true); ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0); renderer.setSeriesPositiveItemLabelPosition(i, itemPosition); renderer.setSeriesNegativeItemLabelPosition(i, itemPosition); } ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0); renderer.setPositiveItemLabelPositionFallback(itemPosition); renderer.setNegativeItemLabelPositionFallback(itemPosition); renderer.setShadowVisible(false); // create the chartpanel ChartPanel chartPanel = new ChartPanel(chart); chart.setBorderVisible(true); return chartPanel; }
From source file:org.toobsframework.pres.chart.ChartUtil.java
public static void configureDomainItemLabels(IRequest componentRequest, BasePlot plot, AbstractRenderer renderer, Map params, boolean is3D) { if (plot.getShowDomainItemLabels()) { String orientation = ParameterUtil.resolveParam(componentRequest, plot.getOrientation(), params, "horizontal")[0]; if (orientation.equals("horizontal")) { ItemLabelPosition position1; if (is3D) { position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.CENTER_LEFT); renderer.setItemLabelAnchorOffset(15.0d); } else { position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); }/* w w w. j av a 2 s. c o m*/ renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setNegativeItemLabelPosition(position2); } else if (orientation.equals("vertical")) { ItemLabelPosition position1; if (is3D) { position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BOTTOM_CENTER); renderer.setItemLabelAnchorOffset(10.0d); } else { position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); } renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setNegativeItemLabelPosition(position2); } renderer.setBaseItemLabelsVisible(true); ((CategoryItemRenderer) renderer).setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a bar chart. The chart object returned by this method uses a * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} * for the domain axis, a {@link NumberAxis} as the range axis, and a * {@link BarRenderer} as the renderer. * /* www. j a v a 2s . 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. */ public static JFreeChart createBarChart(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 CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setBaseNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); } if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a bar chart. The chart object returned by this method uses a * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} * for the domain axis, a {@link NumberAxis} as the range axis, and a * {@link BarRenderer} as the renderer.// w ww . j av a 2s.com * * @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. */ public static JFreeChart createBarChart(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 CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); KIDLYRenderer renderer = new KIDLYRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setBaseNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); } if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); 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 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;/*ww w . j ava 2 s .co 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; }