ios - How can I create a piechart that looks like a pie using CorePlot? -
the graph on left 1 coreplot gallery demo, 1 on right 1 created code below. think i missing in order make actual circular pie:
-(void)configurechart { // 1 - reference graph piechartgraph = [[cptxygraph alloc] initwithframe:self.piechartgraphhostview.bounds]; self.piechartgraphhostview.hostedgraph = piechartgraph; // 2 - create chart piechart = [[cptpiechart alloc] init]; piechart.datasource = self; piechart.delegate = self; // piechart.pieradius = (self.piechartgraphhostview.bounds.size.height * 0.7) / 2; piechart.pieradius = (self.piechartgraphhostview.bounds.size.height * 0.7) / 2; piechart.identifier = piechartgraph.title; piechart.startangle = cptfloat(m_pi_4); piechart.slicedirection = cptpiedirectionclockwise; piechart.borderlinestyle = [cptlinestyle linestyle]; // 3 - create gradient cptgradient *overlaygradient = [[cptgradient alloc] init]; overlaygradient.gradienttype = cptgradienttyperadial; overlaygradient = [overlaygradient addcolorstop:[[cptcolor blackcolor] colorwithalphacomponent:0.0] atposition:0.9]; overlaygradient = [overlaygradient addcolorstop:[[cptcolor blackcolor] colorwithalphacomponent:0.4] atposition:1.0]; piechart.overlayfill = [cptfill fillwithgradient:overlaygradient]; // 4 - add chart graph [piechartgraph addplot:piechart]; piechart.datasource = self; self.dataforchart = [@[@20.0, @30.0, @60.0] mutablecopy]; //self.dataforchart = [@[@20.0, @30.0, @60.0]mutablecopy]; }
i tried copy code demo gallery (class called coreplot coreplot example project here).
what doing wrong? why graph square , not circle?
try edit radius of chart. makes circle. obtain circle square view usualy like:
squareview.radius = view.frame.size.width/2;
you can try on piechart:
piechart.pieradius = piechart.frame.size.width/2;
and way setting 2 times piechart datasource
Comments
Post a Comment