List of usage examples for org.jfree.chart.renderer.category BarRenderer setItemLabelsVisible
public void setItemLabelsVisible(boolean visible)
From source file:fr.paris.lutece.plugins.form.business.GraphTypeBarChart.java
/** * return the JFreeChart BarChart graph//w w w .ja v a 2s . co m * @param listStatistic listStatistic * @param strGraphTitle graph title * @param nGraphThreeDimension true if the graph must be in three dimension * @param nGraphLabelValue true if the labels must appear in the graph * @return the JFreeChart graph associate to the graph type */ //Cration de l'histogramme public static JFreeChart createBarChart(List<StatisticEntrySubmit> listStatistic, String strGraphTitle, boolean nGraphThreeDimension, boolean nGraphLabelValue) { JFreeChart chart; CategoryDataset dataset = createBarChartDataset(listStatistic); if (nGraphThreeDimension) { chart = ChartFactory.createBarChart3D(strGraphTitle, null, null, dataset, PlotOrientation.VERTICAL, true, false, false); } else { chart = ChartFactory.createBarChart(strGraphTitle, null, null, dataset, PlotOrientation.VERTICAL, true, false, false); } CategoryPlot categoryPlot = chart.getCategoryPlot(); CategoryAxis categoryAxis = categoryPlot.getDomainAxis(); CategoryLabelPositions labelPositions = CategoryLabelPositions.UP_45; categoryAxis.setCategoryLabelPositions(labelPositions); BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); if (nGraphLabelValue) { renderer.setItemLabelsVisible(true); DecimalFormat decimalformat1 = new DecimalFormat("#.#"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); if (nGraphThreeDimension) { renderer.setPositiveItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); categoryPlot.setRenderer(renderer); } } return chart; }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) { final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset, PlotOrientation.VERTICAL, true, true, false); final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setNoDataMessage("NO DATA!"); chart.setBackgroundPaint(new Color(245, 245, 255)); chart.setBorderPaint(new Color(204, 204, 204)); chart.setBorderStroke(new BasicStroke(1f)); final LegendTitle legend = chart.getLegend(); legend.setWidth(1000);/*from w w w . j a v a 2s . co m*/ legend.setPosition(RectangleEdge.BOTTOM); final BlockBorder border = new BlockBorder(new Color(204, 204, 204)); legend.setBorder(border); final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot(); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204)); categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setDrawBarOutline(true); final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); renderer.setPositiveItemLabelPosition(itemlabelposition); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); return chart; }
From source file:com.voterData.graph.Graph.java
public static JFreeChart getRaceDistbn2008(Map<String, Double> dataMap) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); for (String key : dataMap.keySet()) { if (key.equals("A_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Asian", "REP"); } else if (key.equals("B_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "REP"); } else if (key.equals("I_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "REP"); } else if (key.equals("O_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Other", "REP"); } else if (key.equals("M_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "REP"); } else if (key.equals("U_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "REP"); } else if (key.equals("W_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "White", "REP"); } else if (key.equals("A_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Asian", "DEM"); } else if (key.equals("B_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "DEM"); } else if (key.equals("I_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "DEM"); } else if (key.equals("O_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Other", "DEM"); } else if (key.equals("M_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "DEM"); } else if (key.equals("U_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "DEM"); } else if (key.equals("W_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "White", "DEM"); } else if (key.equals("A_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Asian", "UNA"); } else if (key.equals("B_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "UNA"); } else if (key.equals("I_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "UNA"); } else if (key.equals("O_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Other", "UNA"); } else if (key.equals("M_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "UNA"); } else if (key.equals("U_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "UNA"); } else if (key.equals("W_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "White", "UNA"); }/*from ww w .j ava 2 s .co m*/ } JFreeChart jfreechart = ChartFactory.createBarChart("Race Distribution - 2008", "Party", "% of votes", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setSeriesPaint(0, Color.ORANGE); renderer.setSeriesPaint(1, Color.MAGENTA); renderer.setSeriesPaint(2, Color.PINK); renderer.setSeriesPaint(3, Color.YELLOW); renderer.setSeriesPaint(4, Color.cyan); renderer.setSeriesPaint(5, Color.RED); renderer.setSeriesPaint(6, Color.green); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); categoryplot.setRenderer(renderer); return jfreechart; }
From source file:com.voterData.graph.Graph.java
public static JFreeChart getRaceDistbn2012(Map<String, Double> dataMap) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); for (String key : dataMap.keySet()) { if (key.equals("A_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Asian", "REP"); } else if (key.equals("B_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "REP"); } else if (key.equals("I_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "REP"); } else if (key.equals("O_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Other", "REP"); } else if (key.equals("M_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "REP"); } else if (key.equals("U_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "REP"); } else if (key.equals("W_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "White", "REP"); } else if (key.equals("A_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Asian", "DEM"); } else if (key.equals("B_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "DEM"); } else if (key.equals("I_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "DEM"); } else if (key.equals("O_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Other", "DEM"); } else if (key.equals("M_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "DEM"); } else if (key.equals("U_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "DEM"); } else if (key.equals("W_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "White", "DEM"); } else if (key.equals("A_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Asian", "UNA"); } else if (key.equals("B_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "UNA"); } else if (key.equals("I_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "UNA"); } else if (key.equals("O_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Other", "UNA"); } else if (key.equals("M_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "UNA"); } else if (key.equals("U_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "UNA"); } else if (key.equals("W_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "White", "UNA"); }/*from ww w. j ava2s . co m*/ } JFreeChart jfreechart = ChartFactory.createBarChart("Race Distribution - 2012", "Party", "% of votes", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setSeriesPaint(0, Color.cyan); renderer.setSeriesPaint(1, Color.pink); renderer.setSeriesPaint(2, Color.red); renderer.setSeriesPaint(3, Color.orange); renderer.setSeriesPaint(4, Color.green); renderer.setSeriesPaint(5, Color.yellow); renderer.setSeriesPaint(6, Color.magenta); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); categoryplot.setRenderer(renderer); return jfreechart; }
From source file:org.bonitasoft.simulation.reporting.jasperreport.BarChartVisibleBarLabel.java
public void customize(JFreeChart chart, JRChart jasperChart) { BarRenderer bsr = (BarRenderer) chart.getCategoryPlot().getRenderer(); bsr.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); bsr.setItemLabelsVisible(true); // Set position of Items label : center bsr.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); bsr.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // If there isn't enough space to draw the ItemLabel... bsr.setPositiveItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER)); bsr.setNegativeItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER)); }
From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java
public static JFreeChart createChart1(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("", // chart title "X-value", // domain axis label "Y-value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );//www . ja v a 2 s . com // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1);// categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // set up gradient paints for series... 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); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setItemLabelAnchorOffset(10D); renderer.setItemLabelFont(new Font("", Font.PLAIN, 12)); renderer.setItemLabelsVisible(true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 180)); // OPTIONAL CUSTOMISATION COMPLETED. chart.getTitle().setFont(new Font("", Font.BOLD, 16));// // domainAxis.setLabelFont(new Font("", Font.BOLD, 14)); // domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10)); // rangeAxis.setLabelFont(new Font("", Font.BOLD, 15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); /** * chart.getTitle().setFont(new Font("",Font.BOLD,20));// // domainAxis.setLabelFont(new Font("",Font.BOLD,14)); // domainAxis.setTickLabelFont(new Font("",Font.BOLD,12)); // rangeAxis.setLabelFont(new Font("",Font.BOLD,15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); */ return chart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo2.java
/** * Creates a chart./* w w w .j a va2 s . co m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.getPlot().setOutlinePaint(null); final TextTitle title = new TextTitle("Figure 8.5 - Case studies are available"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = chart.getCategoryPlot(); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(0.0, 5.0); rangeAxis.setVisible(false); final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null); domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); domainAxis.setCategoryMargin(0.30); domainAxis.addSubLabel("Sm.", "(10)"); domainAxis.addSubLabel("Med.", "(10)"); domainAxis.addSubLabel("Lg.", "(10)"); domainAxis.addSubLabel("All", "(10)"); plot.setDomainAxis(domainAxis); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); renderer.setPositiveItemLabelPosition(position); renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition()); return chart; }
From source file:reports.util.BarChartScriptlet.java
/** * *//*w ww .ja va 2 s. c o m*/ public void afterReportInit() throws JRScriptletException { JFreeChart jfreechart = ChartFactory.createBarChart3D("Bar Chart Demo", // chart title "States", // X Label "Sell Amount", // Y Label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); IntervalMarker intervalmarker = new IntervalMarker(4000D, 5000D); intervalmarker.setLabel("Target Range"); intervalmarker.setLabelFont(new Font("SansSerif", 2, 11)); intervalmarker.setLabelAnchor(RectangleAnchor.LEFT); intervalmarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT); intervalmarker.setPaint(new Color(222, 222, 255, 128)); categoryplot.addRangeMarker(intervalmarker, Layer.BACKGROUND); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setItemLabelsVisible(true); BarRenderer barrenderer = (BarRenderer) categoryitemrenderer; barrenderer.setMaxBarWidth(0.050000000000000003D); barrenderer.setItemLabelGenerator(new LabelGenerator()); barrenderer.setItemLabelsVisible(true); ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -1.5707963267948966D); barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); /* jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setDomainGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer barrenderer = (BarRenderer)categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64)); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0)); GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); barrenderer.setSeriesPaint(0, gradientpaint); barrenderer.setSeriesPaint(1, gradientpaint1); barrenderer.setSeriesPaint(2, gradientpaint2); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D)); */ this.setVariableValue("Chart", new JCommonDrawableRenderer(jfreechart)); }
From source file:org.jfree.chart.demo.WaterfallChartDemo.java
/** * Returns the chart./* w w w . j ava2s .c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category", "Cost Per Unit", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final ValueAxis rangeAxis = plot.getRangeAxis(); // create a custom tick unit collection... final DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(5, formatter)); standardUnits.add(new NumberTickUnit(10, formatter)); standardUnits.add(new NumberTickUnit(20, formatter)); standardUnits.add(new NumberTickUnit(50, formatter)); standardUnits.add(new NumberTickUnit(100, formatter)); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); rangeAxis.setStandardTickUnits(standardUnits); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); final DecimalFormat labelFormatter = new DecimalFormat("$##,###.00"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); // renderer.setLabelGenerator( // new StandardCategoryLabelGenerator("{2}", labelFormatter) // ); renderer.setItemLabelsVisible(true); return chart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo3.java
/** * Creates a chart./* w w w . j a v a2s. c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.getPlot().setOutlinePaint(null); final TextTitle title = new TextTitle("Figure 6 | Overall SEO Rating"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = chart.getCategoryPlot(); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(0.0, 4.0); rangeAxis.setVisible(false); final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null); domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); domainAxis.setCategoryMargin(0.30); domainAxis.addSubLabel("Sm.", "(10)"); domainAxis.addSubLabel("Med.", "(10)"); domainAxis.addSubLabel("Lg.", "(10)"); domainAxis.addSubLabel("All", "(10)"); final CategoryLabelPositions p = domainAxis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); plot.setDomainAxis(domainAxis); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setBaseOutlineStroke(null); // final StandardCategoryLabelGenerator generator = new StandardCategoryLabelGenerator( // "{2}", new DecimalFormat("0.00") // ); // renderer.setLabelGenerator(generator); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition()); return chart; }