core plot - Despite setting xRange, data is plotted in the wrong place -


i'm trying plot histogram. x-axis range should 881 1281 (i've verified i'm using location of 881 , range of 400 when constructing cptplotrange xrange). axis draws correct range, bars end near 2000 (data space), though data source method sending location values between 881 , 1281.

here's code:

- (void) viewdidload {     [super viewdidload];      inputvariable           temp(1081.0, 50.0);     self.hist = new histogram(temp.mean(), temp.stddev(), 5.0);     (histogram::sizet = 0; < 1000; ++i)     {         double v = temp.randomvalue();         self.hist->add(v);     }      const histogram& hist = *self.hist;      cptxygraph* graph = [[cptxygraph alloc] initwithframe: self.chart1.bounds];     graph.fill                = [cptfill fillwithcolor: [cptcolor lightgraycolor]];     graph.cornerradius        = 4.0;     self.chart1.hostedgraph = graph;      self.graph = graph;      // plot area      graph.plotareaframe.fill          = [cptfill fillwithcolor:[cptcolor lightgraycolor]];     graph.plotareaframe.paddingtop    = 4.0;     graph.plotareaframe.paddingbottom = 50.0;     graph.plotareaframe.paddingleft   = 50.0;     graph.plotareaframe.paddingright  = 4.0;     graph.plotareaframe.cornerradius  = 4.0;     graph.plotareaframe.maskstoborder = no;      graph.plotareaframe.axisset.borderlinestyle = [cptlinestyle linestyle];      graph.plotareaframe.plotarea.fill = [cptfill fillwithcolor:[cptcolor whitecolor]];      // setup plot space     cptxyplotspace *plotspace = (cptxyplotspace *)graph.defaultplotspace;     plotspace.xrange     = [cptplotrange plotrangewithlocation:cptdecimalfromdouble(hist.lowvalue()) length:cptdecimalfromdouble(hist.range())];     plotspace.yrange     = [cptplotrange plotrangewithlocation:cptdecimalfromdouble(0.0) length:cptdecimalfromdouble(hist.maxbincount() * 1.2)];     //plotspace.yscaletype = cptscaletypelog;      // line styles     cptmutablelinestyle *axislinestyle = [cptmutablelinestyle linestyle];     axislinestyle.linewidth = 2.0;     //axislinestyle.linecap   = kcglinecapround;      cptmutablelinestyle *majorgridlinestyle = [cptmutablelinestyle linestyle];     majorgridlinestyle.linewidth = 0.75;     majorgridlinestyle.linecolor = [cptcolor redcolor];      cptmutablelinestyle *minorgridlinestyle = [cptmutablelinestyle linestyle];     minorgridlinestyle.linewidth = 0.25;     minorgridlinestyle.linecolor = [cptcolor bluecolor];      // text styles     cptmutabletextstyle *axistitletextstyle = [cptmutabletextstyle textstyle];     axistitletextstyle.fontname = @"helvetica neue bold";     axistitletextstyle.fontsize = 14.0;      // axes     // label x axis fixed interval policy     cptxyaxisset *axisset = (cptxyaxisset *)graph.axisset;     cptxyaxis *x          = axisset.xaxis;     x.separatelayers              = no;     x.orthogonalcoordinatedecimal = cptdecimalfromdouble(0.0);     x.majorintervallength         = cptdecimalfromdouble(0.5);     x.minorticksperinterval       = 4;     x.tickdirection               = cptsignnone;     x.axislinestyle               = axislinestyle;     x.majorticklength             = 12.0;     x.majorticklinestyle          = axislinestyle;     //x.majorgridlinestyle          = majorgridlinestyle;     x.minorticklength             = 8.0;     //x.minorgridlinestyle          = minorgridlinestyle;     x.title                       = @"temperature";     x.titletextstyle              = axistitletextstyle;     x.titleoffset                 = 25.0;     //x.alternatingbandfills        = @[[[cptcolor redcolor] colorwithalphacomponent:0.1], [[cptcolor greencolor] colorwithalphacomponent:0.1]];     x.labelingpolicy              = cptaxislabelingpolicyautomatic;      // label y automatic label policy.     //axislinestyle.linecolor = [cptcolor greencolor];      cptxyaxis *y = axisset.yaxis;     y.separatelayers        = yes;     y.orthogonalcoordinatedecimal = plotspace.xrange.location;//cptdecimalfromdouble(hist.lowvalue());     y.minorticksperinterval = 9;     y.tickdirection         = cptsignnone;     y.axislinestyle         = axislinestyle;     y.majorticklength       = 12.0;     y.majorticklinestyle    = axislinestyle;     //y.majorgridlinestyle    = majorgridlinestyle;     //y.minorticklength       = 8.0;     //y.minorgridlinestyle    = minorgridlinestyle;     y.title                 = @"number of samples";     y.titletextstyle        = axistitletextstyle;     y.titleoffset           = 40.0;     //y.alternatingbandfills  = @[[[cptcolor bluecolor] colorwithalphacomponent:0.1], [nsnull null]];     y.labelingpolicy        = cptaxislabelingpolicyautomatic;      //cptfill *bandfill = [cptfill fillwithcolor:[[cptcolor darkgraycolor] colorwithalphacomponent:0.5]];     //[y addbackgroundlimitband:[cptlimitband limitbandwithrange:[cptplotrange plotrangewithlocation:cptdecimalfromdouble(7.0) length:cptdecimalfromdouble(1.5)] fill:bandfill]];     //[y addbackgroundlimitband:[cptlimitband limitbandwithrange:[cptplotrange plotrangewithlocation:cptdecimalfromdouble(1.5) length:cptdecimalfromdouble(3.0)] fill:bandfill]];       //  set bar plot…      //cptxyplotspace *barplotspace = [[cptxyplotspace alloc] init];     cptxyplotspace *barplotspace = (cptxyplotspace *) self.graph.defaultplotspace;      //barplotspace.xrange = [cptplotrange plotrangewithlocation:cptdecimalfromdouble(0.0) length:cptdecimalfromdouble(200.0)];     //barplotspace.yrange = [cptplotrange plotrangewithlocation:cptdecimalfromdouble(0.0) length:cptdecimalfromdouble(15.00)];     //[self.graph addplotspace:barplotspace];      cptbarplot *barplot = [cptbarplot tubularbarplotwithcolor:[cptcolor darkgraycolor] horizontalbars: false];     barplot.datasource      =   self;      barplot.barsarehorizontal = false;     barplot.barwidth        =   cptdecimalfromdouble(1.0);     barplot.barbasesvary    =   false;     barplot.basevalue       =   cptdecimalfromdouble(0.0);     barplot.baroffset       =   cptdecimalfromdouble(hist.lowvalue());     barplot.identifier      =   @"bar plot";     //barplot.plotrange     =   [cptplotrange plotrangewithlocation:cptdecimalfromdouble(0.0) length:cptdecimalfromdouble(7.0)];      cptmutabletextstyle *whitetextstyle = [cptmutabletextstyle textstyle];     whitetextstyle.color = [cptcolor whitecolor];     //barplot.labeltextstyle    = whitetextstyle;      [self.graph addplot:barplot toplotspace:barplotspace]; }   - (nsuinteger) numberofrecordsforplot: (cptplot*) inplot {     return self.hist->numbins(); }  - (double) doubleforplot: (cptplot*) inplot     field: (nsuinteger) infield     recordindex: (nsuinteger) inidx {     const histogram& h = *self.hist;      if (infield == cptbarplotfieldbarlocation)     {         double v = h.binmid(inidx);         nslog(@"v: %f", v);         return v;     }     else if (infield == cptbarplotfieldbartip)     {         return h[inidx];     }      return 0.0; } 

and resulting graph:

example plot

any idea i'm doing wrong? thanks!

for application, baroffset should 0 (0). offset used displace bars location given datasource. common use separate bars @ same location when plotting multiple bar plots on same graph might have overlapping bars @ common locations.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -