7

I have used AchartEngine to display Barchart. In my chart bar color is visible for 0 values also. I have checked like the following.. but it set all the values to transparent. I want to set the bar color to values having greater than 0.

CategorySeries series = new CategorySeries("");
        for (int i = 0; i < y_onemonth.length; i++) {
            series.add("Bar" + (i + 1), y_onemonth[i]);
        }

        XYMultipleSeriesDataset dataSet = new XYMultipleSeriesDataset();
        dataSet.addSeries(series.toXYSeries()); // number of series

        // customization of the chart

        XYSeriesRenderer renderer = new XYSeriesRenderer();
        for (int i = 0; i < y_onemonth.length; i++) {
        if(y_onemonth[i]==0)
        {
            renderer.setColor(Color.TRANSPARENT);
        }
        else
        {
            renderer.setColor(Color.RED);
        }
        }

Update: I changed my code as you mention, but get the chart like this. I have value for 19th of the month, But it doesn't visible.

enter image description here

Manikandan
  • 1,479
  • 6
  • 48
  • 89

1 Answers1

6

I have had some success replacing 0 values with MathHelper.NULL_VALUE. You can find the documentation for that class here.

EDIT : when filling your data Series, you could try something like this instead :

for (int i = 0; i < y_onemonth.length; i++) {
    double doubleValue = MathHelper.NULL_VALUE;
    if (y_onemonth[i] != 0){
        doubleValue = y_onemonth[i];
    }
    series.add("Bar" + (i + 1), doubleValue);
}

Hope this will help ;-)

2Dee
  • 8,609
  • 7
  • 42
  • 53
  • can you explain it in detail with my issue. I didn't get you. – Manikandan Nov 19 '13 at 14:59
  • Edited my answer, hopefully this is clearer. Basically, the creator of the library once suggested me to use MathHelper.NULL_VALUE instead of 0 to get rid of your undesired bar for 0 values. By changing the color of the Renderer, you actually change the color for the whole set. Let me know if you need me to explain further. – 2Dee Nov 19 '13 at 15:29
  • I updated my code with yours, got the chart like in the update of the question. – Manikandan Nov 19 '13 at 15:45
  • Strange, but the really weird part is that you get one random value that doesn't show... I would suggest you check the content of y_onemonth but apart from that, I don't know how else I could help you. Sorry :-/ – 2Dee Nov 19 '13 at 16:03