Monday, August 29, 2011

Complete Guide for Pie Chart and Fragmented Pie Chart (MIM Chart Lib)

So our data looks like following and we will make pie chart of the Income column.
Code is in XCode proj > HowToUseFiles> TestClass.m

     [MIMColor InitColors];

    NSString *csvPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myTable.csv"];
    MIMPieChart *pieChartView=[[MIMPieChart alloc]initWithFrame:CGRectMake(40, 40, 600, 500)];
    pieChartView.radius=200;
    pieChartView.tint=BEIGETINT;// Available Tints: GREENTINT,REDTINT,BEIGETINT
    [pieChartView readFromCSV:csvPath  TitleAtColumn:0  DataAtColumn:4];
    [pieChartView drawPieChart];
    [self.view addSubview:pieChartView];



It will make the pie chart look like following, you can change the tint color to see what they look like OR you can GO TO THIS POST to see them. If you tap on a region of pie chart, the respective information label gets highlighted, as in this case Indonesia is highlighted.



























Now lets look at fragmented piechart , for now we can give data only through arrays, I need to add support for csv format. But you can use it as following as in XCode proj > HowToUseFiles> TestClassFragmented.m


      [MIMColor InitColors];
    
    _DFragmentedDoughNut *detailedDoughNut=[[_DFragmentedDoughNut alloc]initWithFrame:CGRectMake(0, 0, 600, 600)];
    detailedDoughNut.tint=GREENTINT;// Available Tints: GREENTINT,REDTINT,BEIGETINT
    detailedDoughNut.isShadow=YES;
    [detailedDoughNut setValuesArray:[NSArray arrayWithObjects:@"23",@"45",@"89",@"123",@"21",@"144", nil]];
    [detailedDoughNut setTitleArray:[NSArray arrayWithObjects:@"U.P.",@"Bihar",@"Delhi",@"Punjab",@"Haryana",@"Rajasthan", nil]];
    [detailedDoughNut setOutRadius:200 AndInnerRadius:300];
    [self.view addSubview:detailedDoughNut];
    
Output looks like following






























Entire Guide can be found HERE along with downloadables.

5 comments:

  1. hello reetu.. wonderful work.
    a great suggestion: can you add animations to the pie charts? like gesture based rotation..? i recommend your library to many ppl these days..awesome job.

    ReplyDelete
  2. Hello reetu..the pie chart faces an issue with plotting when i use iOS 5.0 simulator..could you rectify it? also could you add animations like rotation,pinch to zoom etc?

    ReplyDelete
  3. When I try to hightlight titles, the application crashes in iOS 5.0 simulator... Any suggestions??

    ReplyDelete
  4. Hi,
    Actually i am implementing this graph for iPhone, but it shows iPad sized graph in iphone,
    so i reduced the size of the frame but the pie and its values get jumbled up... i am not able to find any solution..
    Can someone pls help!!

    ReplyDelete
  5. How can we add feature to zoom in/out ?

    ReplyDelete