Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Labels on stacked vertical bar

2005-11-07
2013-01-13
  • Hi,

    I'm trying to display labels on top oif each bar in the chart.
    I have used a preprocessor using implementing following code

    public class AlarmChartPostProcessor implements ChartPostProcessor 

        public void processChart( Object chart, Map params ) 
        { 
            CategoryPlot plot = (CategoryPlot)((JFreeChart)chart).getPlot(); 
            CategoryItemRenderer r1=(CategoryItemRenderer)plot.getRenderer();
            r1.setItemLabelsVisible(new Boolean(true));       
        } 
    }

    I get no errors, but the labels are not displayed. Is it possible that no labels are available? do I have to fill the values for the labels, or does this go automaticly?

     
    • I have managed to make it work partialy.
      I used this code for my preprocessor

      public class AlarmChartPostProcessor implements ChartPostProcessor 

          public void processChart( Object chart, Map params ) 
          { 
              CategoryPlot plot = (CategoryPlot)((JFreeChart)chart).getPlot(); 
              CategoryItemRenderer r1=(CategoryItemRenderer)plot.getRenderer();
              r1.setItemLabelsVisible(new Boolean(true));       
              CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{0}", new DecimalFormat("0"));
              r1.setItemLabelFont(new Font("Serif", Font.PLAIN, 10));
              r1.setItemLabelGenerator(generator);   
             
          } 
      }

      The only problem is that the labels are displayed inside the bar, not above it. Due to the fact that the values in the chart tend to be wide apart (0-15000), the lower values are not displayed because the bar is not high enough.

      Is it possible to place the labels above the bars?