1

I have created bar graph using AChartEngine library. Currently i am getting the two years revenue(2011 & 2012) and comparing them month wise. So in each bar, i am displaying two years data and displaying them Monthly (like Jan, Feb etc). But my requirement is, i have to display it quarterly..like the below picture:

Bar Image

Here is my current implementation:

Implemented Code

Current Bar Graph Image

So where i need to change the code so i can implement the above bar graph?? Please help..

4
  • i have clear idea about what you have already done but from this image i could not able to get what you want to do. can you please briefly describe it once again? What Do you mean by Quarterly? Oct 15, 2012 at 12:30
  • See, I suppose got 2011 and 2012 monthly data. Now for the first three months(First Quarter, Q1), i have to display the data in 3 bars means each for Jan, Feb and March. Now again there should be space and have to display the next three months data(Q2). So each bar is containing the comparison between 2011 and 2012. Oct 15, 2012 at 12:40
  • @Bhavesh Can you please help me to change the color of the bars for 2012 datas?? Oct 15, 2012 at 13:49
  • @ArindamMukherjee hi i need your help in implementing the same can you please help
    – Goofy
    Feb 4, 2013 at 6:27

2 Answers 2

3

as Dan have Rightly said you can manage your space by passing null value in certain place. i would like to give your solution for the Question you have asked to dan: how i will display the Q1, Q2 instead of 1, 2 , 3 etc..in the x-axis??

Answer : if you have 0 to 12 Digits in X Axis.

you can manage the X Axis Text Lables by the Below Method.

renderer.addXTextLabel("X AXIS POSITION IN INTEGER","YOUR QUARTER STRING IN STRING");

LIKE BELOW(i have put it according to your Question):

renderer.addXTextLabel(2,"Q1");

renderer.addXTextLabel(6,"Q2");

renderer.addXTextLabel(10,"Q3");

renderer.addXTextLabel(14,"Q4");

EDITED

For Chaging Colors of Bar : 

you can set below code as Below :

int[] colors = new int[] { Color.parseColor("#4C4646"),
                    Color.parseColor("#71A700") };
            XYMultipleSeriesRenderer renderer;
            renderer = buildBarRenderer(colors);

and put Method is Below buildBarRenderer:

protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors) {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

        renderer.setAxisTitleTextSize(18);
        renderer.setChartTitleTextSize(18);
        renderer.setLabelsTextSize(18);
        renderer.setLegendTextSize(18);
        int length = colors.length;
        for (int i = 0; i < length; i++) {
            SimpleSeriesRenderer r = new SimpleSeriesRenderer();
            r.setColor(colors[i]);
            renderer.addSeriesRenderer(r);
        }
        return renderer;
    }
5
  • Hey..i already did this..it is coming..only color is not coming properly for the bars.. Oct 15, 2012 at 13:50
  • No, My requirement is lil different. Suppose take Q1. for Q1, month of Jan, bar color will be Gray and Blue. For Month of Feb, bar color will be Gray and Red and For Month of March, bar color will be Gray and yellow..just check the image..i need same like the above.. Oct 15, 2012 at 13:57
  • Hi Bhavesh..I am still unable to resolve the color issue..how can we change the color of the bars Oct 16, 2012 at 7:00
  • @ArindamMukherjee : i think you should be able to change colors of the Bar Using the Above method. and pass the Type Parameter as Type.STACKED. i am getting changes in color in my Project. could you give me reason where you are sticking right now? Oct 16, 2012 at 7:21
  • i am able to change the color..but for the first bar, i need two colors, Gray and Red, for second Bar: Need two colors,Gray, Blue and for third Bar: need two colors, Gray and yellow.. Oct 16, 2012 at 7:24
1

You could add some null values between the quarter values such as you will get the space you need.

9
  • Ok..But then how i will display the Q1, Q2 instead of 1, 2 , 3 etc..in the x-axis?? Oct 15, 2012 at 13:15
  • After adding the null values, i got some spaces..how i will write the q1, q2 instead of 0, 1 ,2.. Oct 15, 2012 at 13:34
  • Hi, Guys..i am able to display the Q1, Q2 etc properly..But now i require some changes in the colors of each bar..for 2011 and in the month of Jan, i am showing the color as Gray and 2012 as blue..so in the single bar, i am getting two colors..But for the month of Feb, i need the 2011 color as Gray and 2012 Color as Red..and for March, it should be Gray and yellow..How can i make this changes..please help me.. Oct 15, 2012 at 13:41
  • The color is controlled by the renderer and each series has a renderer. You will have to have multiple series in order to have multiple colors.
    – Dan D.
    Oct 15, 2012 at 14:04
  • in the buildBarRenderer(colors), if we add multiple colors, can we will be able to implement this..?? Oct 15, 2012 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.