How to get bars with maximum and minimum heights in JfreeCharts Barchart and set them with different color ?

0

I want to get the minimum and maximum value in bar chart and set them with different colors...

aamitt06's picture
147
Joined: Jun 23 2014 - 5:48am
Last seen: 3 years 5 months ago

1 Answer:

0

I resolved the issue by making customized BarRenderer class here is what I did to resolve this:

  public void customize(JFreeChart chart, JRChart jasperChart) {
           
        //Set the Customized Bar Renderer
        CustomBarRenderer renderer = new CustomBarRenderer();
        chart.getCategoryPlot().setRenderer((CategoryItemRenderer) renderer);
         
    }

 

And Here is code for customized bar renderer class:

 

public class CustomBarRenderer extends BarRenderer  {
    
    public CustomBarRenderer(){
       // super(
    }
    @Override
    public Paint getItemPaint(int row,int column){

        CategoryDataset dataset = getPlot().getDataset();
        
        if(dataset!=null)
        {
        Number maximum = DatasetUtilities.findMaximumRangeValue(dataset);
        Number minimum = DatasetUtilities.findMinimumRangeValue(dataset);
                
        double l_value  = dataset.getValue(row, column).doubleValue();
        if(l_value==(double)minimum)
        {
            return Color.RED;
        }
        else if(l_value==(double)maximum) {
            return Color.GREEN;
        }
        
        }     
            return Color.GRAY;   
      }

}
 

aamitt06's picture
147
Joined: Jun 23 2014 - 5:48am
Last seen: 3 years 5 months ago
Feedback