Categorzing values and changing color based on condition in StackedBarChart

0

I am working in JasperStudio and customizing a **StackedBarChart** to show it values like this.    
   
I have written the below code    

    
    static class CustomBarRenderer extends BarRenderer {
        /**
        *
        */
        private static final long serialVersionUID = 1L;

        public CustomBarRenderer() {
            super();
        }

        public Paint getItemPaint(int row, int column) {
            Color color = null;
            CategoryDataset cd = getPlot().getDataset();
        
            if (cd != null) {
                String l_rowKey = (String) cd.getRowKey(row);
                String l_colKey = (String) cd.getColumnKey(column);
                double l_value = cd.getValue(l_rowKey, l_colKey).doubleValue();
                if (l_value < 70) {// red
                    color = new Color(231, 104, 110);
                } // yellow
                else if (l_value >= 70 && l_value <= 90) {
                    color = new Color(255, 190, 6);
                }
                //green
                else if (l_value > 90) {
                    color = new Color(5, 176, 76);
                }

            }
            return color;
        }
    }

and called it using:    

        public void customize(JFreeChart chart, JRChart jrChart) {
        CustomBarRenderer renderer = new CustomBarRenderer();
        chart.getCategoryPlot().setRenderer(renderer);}

but it produces the following output which is totally strange to me. it creates separate bars whereas I want the results on the same bar. Is there any way I could get it stacked fulfilling the above conditions? Thanks    
 
     

If I try this code, It doesn't produce the seprate bars but doesn't categories the results.    

     CategoryPlot cplot = (CategoryPlot)chart.getPlot();
   
     //set bar chart color
 
     ((BarRenderer)cplot.getRenderer()).setBarPainter(new StandardBarPainter());
 
     BarRenderer r = (BarRenderer)chart.getCategoryPlot().getRenderer();
     r.setSeriesPaint(0, new Color(231,104,110)); r.setSeriesPaint(1, new
     Color(255,190,6)); r.setSeriesPaint(2, new Color(5,176,76));
 
I am having three category series in my chart in Jasper report    
   
 

 

jamshaidiqbal120's picture
Joined: Nov 25 2019 - 11:04am
Last seen: 3 days 13 hours ago

0 Answers:

No answers yet
Feedback
randomness