ios - How to plot grouped bar graph in core plot? -


i implementing bar charts using core plot. last 3 days not implementing grouped graphs in ios. grouped bar charts means multiple bar charts on x-axis.

- (void)generatelayout {     graph                               = [[cptxygraph alloc] initwithframe:cgrectzero];     [graph applytheme:[cpttheme themenamed:kcptplainwhitetheme]];// can change theme color here........     self.hostedgraph                    = graph;     graph.plotareaframe.maskstoborder   = no;     graph.paddingleft                   = 10.0f;     graph.paddingtop                    = 210.0f;       // alter size of graph top position........     graph.paddingright                  = 80.0f;     graph.paddingbottom                 = 90.0f;      cptmutablelinestyle *borderlinestyle    = [cptmutablelinestyle linestyle];     borderlinestyle.linecolor               = [cptcolor blackcolor];              // color boundary of graph....     borderlinestyle.linewidth               = 2.0f;        // graph style/shape change in x or y coordinate...........     graph.plotareaframe.borderlinestyle     = borderlinestyle;     graph.plotareaframe.paddingtop          = 10.0;     graph.plotareaframe.paddingright        = 10.0;     graph.plotareaframe.paddingbottom       = 80.0;     graph.plotareaframe.paddingleft         = 70.0;       plotspace.allowsuserinteraction=yes;     plotspace.globalxrange          = [cptplotrange plotrangewithlocation:cptdecimalfromint(-1)                                                                    length:cptdecimalfromint([dates count]+3)];       plotspace.delegate              = self;     nslog(@"set count=======%d",sets.count);//    6     plotspace.yrange                = [cptplotrange plotrangewithlocation:cptdecimalfromint(0)                                                                    length:cptdecimalfromint(200)];     plotspace.xrange                = [cptplotrange plotrangewithlocation:cptdecimalfromint(-1)// take x , 0 or other coordiante.....                                                                    length:cptdecimalfromint(7)];      cptmutablelinestyle *majorgridlinestyle = [cptmutablelinestyle linestyle];     majorgridlinestyle.linewidth            = 2.75;     majorgridlinestyle.linecolor            = [[cptcolor blackcolor] colorwithalphacomponent:0.5];     cptmutablelinestyle *minorgridlinestyle = [cptmutablelinestyle linestyle];     minorgridlinestyle.linewidth            = 2.25;     minorgridlinestyle.linecolor            = [[cptcolor blackcolor] colorwithalphacomponent:0.5];      cptxyaxisset *axisset = (cptxyaxisset *)graph.axisset;         cptxyaxis *x                    = axisset.xaxis;      x.orthogonalcoordinatedecimal   = cptdecimalfromint(0);     x.majorintervallength           = cptdecimalfromint(1);//majorintervallength defines number of units between “big” ticks on axis. in case it’s set show 1 every 10 units.     x.minorticksperinterval         = 0;     x.labelingpolicy                = cptaxislabelingpolicynone;     x.majorgridlinestyle            = majorgridlinestyle;     x.axisconstraints               = [cptconstraints constraintwithloweroffset:0.0];        //x labels     int labellocations = 0;     nsmutablearray *customxlabels = [nsmutablearray array];     (nsstring *day in dates)     {         cptaxislabel *newlabel = [[cptaxislabel alloc] initwithtext:day textstyle:x.labeltextstyle];         newlabel.ticklocation   = [[nsnumber numberwithint:labellocations] decimalvalue];         newlabel.offset         = x.labeloffset + x.majorticklength;         [customxlabels addobject:newlabel];         labellocations++;         [newlabel release];     }     x.axislabels                    = [nsset setwitharray:customxlabels];      cptxyaxis *y            = axisset.yaxis;     y.title                 = @"calories burnt (kcal)";     y.titleoffset           = 50.0f;                            //set x-axis label(calories burnt)     y.labelingpolicy        = cptaxislabelingpolicyautomatic;     y.majorgridlinestyle    = majorgridlinestyle;     y.minorgridlinestyle    = minorgridlinestyle;     y.axisconstraints       = [cptconstraints constraintwithloweroffset:0.0];     y.orthogonalcoordinatedecimal=cptdecimalfromfloat(0.0f);       cptxyaxis *y2 = (cptxyaxis *)[[cptxyaxis alloc] initwithframe:cgrectzero];     cptxyplotspace *plotspace2 = [[cptxyplotspace alloc] init];     plotspace2.xrange = plotspace.xrange;     plotspace2.yrange = [cptplotrange plotrangewithlocation:cptdecimalfromfloat(0) length:cptdecimalfromfloat(60)];     [graph addplotspace:plotspace2];     y2.plotspace = plotspace2;     y2.coordinate = cptcoordinatey;     y2.orthogonalcoordinatedecimal = cptdecimalfromfloat(6.2);     y2.majorintervallength = cptdecimalfromfloat(5.0f);     y2.minorticksperinterval       = 0;      y2.title                       = @"temperature";     y2.titlelocation               = cptdecimalfrominteger(30.0);    //this used set title of second y-axis..     y2.titletextstyle              =x.titletextstyle;     y2.titleoffset                 =-35.0f;      graph.axisset.axes = [nsarray arraywithobjects :x,y,y2,nil];      cptmutablelinestyle *barlinestyle   = [[[cptmutablelinestyle alloc] init] autorelease];     barlinestyle.linewidth              = 1.0;     barlinestyle.linecolor              = [cptcolor clearcolor];     cptmutabletextstyle *whitetextstyle = [cptmutabletextstyle textstyle];     whitetextstyle.color                = [cptcolor whitecolor];        (nsstring *set in [[sets allkeys] sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)])     {         cptbarplot *plot        = [cptbarplot tubularbarplotwithcolor:[cptcolor bluecolor] horizontalbars:no];         plot.linestyle          = barlinestyle;         cgcolorref color        = ((uicolor *)[sets objectforkey:set]).cgcolor;         plot.fill               = [cptfill fillwithcolor:[cptcolor colorwithcgcolor:color]];         if (firstplot)         {             plot.barbasesvary   = no;             firstplot           = no;         }         else         {             plot.barbasesvary   = yes;         }         plot.barwidth           = cptdecimalfromfloat(0.5f);         plot.barsarehorizontal  = no;         plot.datasource         = self;         plot.identifier         = set;         [graph addplot:plot toplotspace:plotspace];     }       cptlegend *thelegend      = [cptlegend legendwithgraph:graph];     thelegend.numberofrows    = sets.count;     thelegend.fill            = [cptfill fillwithcolor:[cptcolor colorwithgenericgray:0.15]];     thelegend.borderlinestyle = barlinestyle;     thelegend.cornerradius    = 10.0;     thelegend.swatchsize      = cgsizemake(15.0, 15.0);     whitetextstyle.fontsize   = 18.0;     thelegend.textstyle       = whitetextstyle;     thelegend.rowmargin       = 5.0;     thelegend.paddingleft     = 10.0;     thelegend.paddingtop      = 10.0;     thelegend.paddingright    = 10.0;     thelegend.paddingbottom   = 10.0;     graph.legend              = thelegend;     graph.legendanchor        = cptrectanchortopleft;     graph.legenddisplacement  = cgpointmake(80.0, -200.0);   } 

use baroffset property shift plots off given bar location slightly. example, 3 plots, might give first plot offset of -0.2, second offset of 0 (the default), , third offset of +0.2, assuming bars 1 location unit apart.


Comments