Bar chart using achartengine

前端 未结 4 1737
花落未央
花落未央 2020-12-08 05:34

I want to draw a bar chart which contains five individual bars - I have used Achartengine. I am able to display all five bars in the same color but I want to differentiate o

4条回答
  •  离开以前
    2020-12-08 06:14

    I made a hack to achieve this effect. Org.achartengine.SimpleSeriesRenderer changed the class, I added an int[] colors and a boolean multipleColorsEnabled with its getters and setters. So, I changed, org.achartengine.BarChart in class, the method drawSeries, where is set the color of each bar in a loop, as follows:

    int j = startIndex;
    for (int i = 0; i < length; i += 2) {
        if (seriesRenderer.isMultipleColorsEnabled()) {
            paint.setColor(seriesRenderer.getColors()[j++]);
        } else {
            paint.setColor(seriesRenderer.getColor());
        }
        float x = points[i];
        float y = points[i + 1];
        drawBar(canvas, x, yAxisValue, x, y, halfDiffX, seriesNr,
            seriesIndex, paint);
    }
    

    In the class that loads the data used:

    seriesRenderer.setMultipleColorsEnabled(true);
    seriesRenderer.setColors(myColors);
    

提交回复
热议问题