List of usage examples for org.jfree.chart.renderer.category CategoryItemRenderer setItemLabelGenerator
public void setItemLabelGenerator(CategoryItemLabelGenerator generator);
From source file:org.posterita.core.BarChart.java
public JFreeChart createChart() throws OperationException { if (dataset == null) { throw new OperationException("Cannot create Bar chart: cause -> dataset empty!"); }//w ww . j av a 2s . co m switch (type) { case BARCHART_FLAT: chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, orientation, showLegend, showTooltip, true); break; case BARCHART_3D: chart = ChartFactory.createBarChart3D(title, xLabel, yLabel, dataset, orientation, showLegend, showTooltip, true); break; default: throw new OperationException( "Invalid barchart type! Can only be BarChart.BARCHART_FLAT or BarChart.BARCHART_3D"); } //setting subtitle if (subtitle != null) { TextTitle title = new TextTitle(subtitle); chart.addSubtitle(title); } CategoryPlot plot = chart.getCategoryPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); //setting tickUnits if (integerTickUnits) axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer barRender = (BarRenderer) plot.getRenderer(); barRender.setMaximumBarWidth(maximumBarWidth); //displaying labels if (showLabels) { CategoryItemRenderer itemRender = plot.getRenderer(); itemRender.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); itemRender.setItemLabelsVisible(true); } return chart; }
From source file:Visuals.BarChart.java
public ChartPanel drawBarChart() { DefaultCategoryDataset bardataset = new DefaultCategoryDataset(); bardataset.addValue(new Double(low), "Low (" + low + ")", lowValue); bardataset.addValue(new Double(medium), "Medium (" + medium + ")", mediumValue); bardataset.addValue(new Double(high), "High (" + high + ")", highValue); bardataset.addValue(new Double(critical), "Critical (" + critical + ")", criticalValue); JFreeChart barchart = ChartFactory.createBarChart(title, // Title riskCategory, riskCountTitle, bardataset // Dataset );// w w w.j a v a 2 s . c om final CategoryPlot plot = barchart.getCategoryPlot(); CategoryItemRenderer renderer = new CustomRenderer(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator(riskCountTitle, NumberFormat.getInstance())); DecimalFormat df = new DecimalFormat("##"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df)); Font m1Font; m1Font = new Font("Cambria", Font.BOLD, 16); renderer.setItemLabelFont(m1Font); renderer.setItemLabelPaint(null); //barchart.removeLegend(); plot.setRenderer(renderer); //renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE5, TextAnchor.CENTER)); //renderer.setItemLabelsVisible(true); barchart.getCategoryPlot().setRenderer(renderer); LegendItemCollection chartLegend = new LegendItemCollection(); Shape shape = new Rectangle(10, 10); chartLegend.add(new LegendItem("Low (" + low + ")", null, null, null, shape, new Color(230, 219, 27))); chartLegend .add(new LegendItem("Medium (" + medium + ")", null, null, null, shape, new Color(85, 144, 176))); chartLegend.add(new LegendItem("High (" + high + ")", null, null, null, shape, new Color(230, 90, 27))); chartLegend.add( new LegendItem("Critical (" + critical + ")", null, null, null, shape, new Color(230, 27, 27))); plot.setFixedLegendItems(chartLegend); plot.setBackgroundPaint(new Color(210, 234, 243)); ChartPanel chartPanel = new ChartPanel(barchart); return chartPanel; }