2

Today I am come across a problem in Drawing out Graph in Android Pro-grammatically. I am Using Achartengine graph library for achieving this , I have done with simple pie chart , But I have no clue how to make Concentric pie chart using this .

Here is a demo Image of graph which I want to make.

Thanx for help in advance :) enter image description here

GOLDEE
  • 2,318
  • 3
  • 25
  • 49
  • so you want to make donut graph..not Pie graph..right ?? – Abhijit Muke Dec 13 '13 at 06:24
  • ohh yeah.. this is donut graph , yes i want this.. i thing you have done this before , coz i came across a thread related to this ..tht war ur's ...so have you implemented that ?? – GOLDEE Dec 13 '13 at 06:25

3 Answers3

3

Here is the example, first create a LinearLayout in your view(xml) and get it in your activityto pass it SingleDonutGraph class to draw a donut graph on this layout.You also have to pass graphValues[]as double array(the value you have to set on donut graph).

LayoutToDisplayChartLeftGraph = (LinearLayout) findViewById(R.id.right_graph_for_punch_count);
Intent achartIntentLeft = new SingleDonutGraph().execute(TabletPunchCountActivity.this, LayoutToDisplayChartLeftGraph,graphValues);

Then use this class SingleDonutGraph.java

public class SingleDonutGraph {
private GraphicalView mChartView2;
static int count = 3;

int[] Mycolors = new int[] { Color.parseColor("#F2846B"),
        Color.parseColor("#A01115"), Color.parseColor("#741E1E") };
String[] labels = { "TODAY", "AVERAGE", "TOTAL" };


public Intent execute(Context context, LinearLayout parent,double values[]) {
    parent.removeAllViews();
    int[] colors = new int[count];
    for (int i = 0; i < count; i++) {
        colors[i] = Mycolors[i];
    }
    DefaultRenderer renderer = buildCategoryRenderer(colors);
    renderer.setShowLabels(false);
    renderer.setBackgroundColor(Color.BLACK);
    renderer.setPanEnabled(false);// Disable User Interaction
    renderer.setScale((float) 1.4);
    renderer.setInScroll(true); //To avoid scroll Shrink        
    renderer.setStartAngle(90);
    renderer.setShowLegend(false);


    MultipleCategorySeries categorySeries = new MultipleCategorySeries(
            "Punch Graph");
    categorySeries.add(labels, values);

    mChartView2 = ChartFactory.getDoughnutChartView(context,
            categorySeries, renderer);

    parent.addView(mChartView2);

    return ChartFactory.getDoughnutChartIntent(context, categorySeries,
            renderer, null);
}

protected DefaultRenderer buildCategoryRenderer(int[] colors) {
    DefaultRenderer renderer = new DefaultRenderer();
    for (int color : colors) {
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(color);
        renderer.addSeriesRenderer(r);

    }
    return renderer;
}
}
Abhijit Muke
  • 1,194
  • 3
  • 16
  • 41
  • how can i add text on it and how can i provide a small circular margin b/w central circle and outer chart – GOLDEE Dec 13 '13 at 08:31
  • To add text on it, you should have to shift to RelativyLayout instead of LinearLayout..try with RealativeLayout CenterInParent align property.. – Abhijit Muke Dec 13 '13 at 09:57
  • and one more thing Abhijit how can i put margin ring after hollow black circle – GOLDEE Dec 13 '13 at 10:10
1

Try this

may b it will help you . Thanks!

Mohit Rakhra
  • 165
  • 9
0

This two lines makes the difference :

mChartView2 = ChartFactory.getDoughnutChartView(context, categorySeries, renderer);

parent.addView(mChartView2);

return ChartFactory.getDoughnutChartIntent(context, categorySeries,
        renderer, null);
GOLDEE
  • 2,318
  • 3
  • 25
  • 49