ios - how can I add an ellipse to a coreplot bargraph -


the image ellipse on bar graph desired result. inherited code creates bar graph displays persons blood pressure. have been tasked plotting ellipse on top of bar graph display person heart rate. i"m using same x-axis believe need add y-axis. here's code. added second plotspace (plotspace2) , y-axis (righty). assistance appreciated

    @interface bpgraphview()      @property (nonatomic) cptxygraph* graph;     @property (nonatomic) cptbarplot* plot;     @property (nonatomic) cptscatterplot* plotgoal;     @property (nonatomic) cptbarplot* plotheartrate;      @end      @implementation bpgraphview       - (void)layoutsubviews {       [super layoutsubviews];       [self setupgraph];       [self setupaxes];       [self setupgoalannotation];       [self.graph reloaddata];      }        - (void)setupgraph {          if (!self.graph) {           self.graph = [[cptxygraph alloc] init];          self.hostedgraph = self.graph;          self.graph.paddingtop    = 0;          self.graph.paddingbottom = 0;          self.graph.paddingleft   = 0;          self.graph.paddingright  = 0;           // need rasterize graph, otherwise performance poor    when scrolling          self.layer.shouldrasterize = yes;           uiparam* uiparam = [uiparam shareduiparam];           // single dashed line showing daily goal          self.plotgoal = [[cptscatterplot alloc] init];          [self.graph addplot:self.plotgoal];          self.plotgoal.datasource = self;          cptmutablelinestyle *linestyledash = [[cptmutablelinestyle alloc] init];          linestyledash.linewidth = 2;          linestyledash.linecolor = [cptcolor   colorwithcgcolor:uiparam.colorgoalline.cgcolor];     //        linestyledash.dashpattern = @[ @7, @3 ];          linestyledash.linejoin = kcglinejoinround;          self.plotgoal.datalinestyle = linestyledash;           self.plot = [[cptbarplot alloc] init];          [self.graph addplot:self.plot];          self.plot.datasource = self;           self.plot.fill = [[cptfill alloc] initwithcolor:[cptcolor colorwithcgcolor:[[uicolor colorwithhexstring:kbarcolorstring] cgcolor]]];          self.plot.linestyle = nil;           self.graph.defaultplotspace.allowsuserinteraction = no;   }          self.graph.frame = self.bounds;          self.plot.frame = cgrectmake(0.0, 0.0, self.bounds.size.width,   self.bounds.size.height - 10.0); }           - (void)setupaxes {           // plot space ranges           //int dailygoal = 0;//[self.data.stepssummary.dailystepsgoal.steps intvalue];          float maxy = 190.0;           (ymbpseries* bpentry in self.data.bpseries) {           if (bpentry.systolic > maxy)        {          maxy = bpentry.systolic;        }     }           nslog(@"maxy = %f", maxy);  // todo: temp debug           cptxyplotspace* plotspace =   (cptxyplotspace*)self.graph.defaultplotspace;         if (self.data.dayinterval == ymdayinterval7day) {         plotspace.xrange = [cptplotrange   plotrangewithlocation:cptdecimalfromfloat(-2)  length:cptdecimalfromfloat(9)]; // 7 values + little before y axis labels         }         else {         plotspace.xrange = [cptplotrange   plotrangewithlocation:cptdecimalfromfloat(-4)  length:cptdecimalfromfloat(18)]; // 14 values + little before y axis labels         }          plotspace.yrange = [cptplotrange  plotrangewithlocation:cptdecimalfromfloat(-maxy * .10)  length:cptdecimalfromfloat(maxy * 1.4)]; // add space before (for  labels) , after         self.plot.barwidth = cptdecimalfromfloat(0.25);        //heartrate plot       cptxyplotspace* plotspace2 = [[cptxyplotspace alloc] init];       plotspace2.xrange = plotspace.xrange;       plotspace2.yrange = [cptplotrange   plotrangewithlocation:cptdecimalfromfloat(0.0)  length:cptdecimalfromfloat(400.0)];       [_graph addplotspace:plotspace2];         // axes       cptxyaxisset *axisset = (cptxyaxisset *)self.graph.axisset;        cptxyaxis *xaxis = axisset.xaxis;       xaxis.majorintervallength = cptdecimalfromint(1);       xaxis.orthogonalcoordinatedecimal = cptdecimalfromint(0);       xaxis.majorgridlinestyle = nil;       xaxis.minorgridlinestyle = nil;       xaxis.majorticklinestyle = nil;       xaxis.minorticklinestyle = nil;       xaxis.axislinestyle = nil;       xaxis.labelingpolicy = cptaxislabelingpolicynone;       cptmutabletextstyle* textstyle = [cptmutabletextstyle textstyle];       textstyle.fontname = klabelfontname;       textstyle.fontsize = font_size_axis_label;       textstyle.color = [cptcolor blackcolor];       xaxis.labeltextstyle = textstyle;       xaxis.axislabels = [graphutil xaxislabels:self.data.dayinterval  start:self.data.startdate style:xaxis.labeltextstyle lefttext:nil];        cptxyaxis *yaxis  = axisset.yaxis;       yaxis.majorintervallength = cptdecimalfromint(10);       yaxis.minorticksperinterval = 0;       yaxis.orthogonalcoordinatedecimal = cptdecimalfrominteger(0);        //setup heart rate yaxis       cptxyaxis *righty = [(cptxyaxis *)[cptxyaxis alloc]  initwithframe:cgrectzero];       righty.coordinate = cptcoordinatey;       righty.plotspace = plotspace2;       righty.orthogonalcoordinatedecimal = cptdecimalfrominteger(0);        cptmutablelinestyle *majorgridlinestyle = [cptmutablelinestyle linestyle];       majorgridlinestyle.linewidth = 0.20;       majorgridlinestyle.linecolor = [cptcolor lightgraycolor];        yaxis.majorgridlinestyle = majorgridlinestyle;       yaxis.minorgridlinestyle = nil;       yaxis.majorticklinestyle = nil;       yaxis.minorticklinestyle = nil;       yaxis.axislinestyle = nil;       yaxis.labelingpolicy = cptaxislabelingpolicyautomatic;       yaxis.preferrednumberofmajorticks = 8;       nsnumberformatter *labelformatter = [[nsnumberformatter alloc] init];       labelformatter.numberstyle = nsnumberformatterdecimalstyle;       yaxis.labelformatter = labelformatter;       yaxis.labeloffset = 0;      //  yaxis.titleoffset = 54;       yaxis.title = @"mmhg";        righty.majorgridlinestyle = majorgridlinestyle;       righty.minorgridlinestyle = nil;       righty.majorticklinestyle = nil;       righty.minorticklinestyle = nil;       righty.axislinestyle = nil;       righty.labelingpolicy = cptaxislabelingpolicyautomatic;       righty.preferrednumberofmajorticks = 8;       nsnumberformatter *labelformatter2 = [[nsnumberformatter alloc] init];       labelformatter.numberstyle = nsnumberformatterdecimalstyle;       righty.labelformatter = labelformatter2;       righty.labeloffset = 0;       righty.title = @"bpm";        nsmutablearray* exclusionranges = [nsmutablearray array];       //  // not label 0       //  [exclusionranges addobject:[cptplotrange   plotrangewithlocation:cptdecimalfromfloat(1)  length:cptdecimalfromfloat(-99999)]];      //        //  // not label daily goal, or nearby, because gets custom annotation      //  if (dailygoal > 0) {     //    [exclusionranges addobject:[cptplotrange   plotrangewithlocation:cptdecimalfromfloat(dailygoal - maxy*0.05) length:cptdecimalfromfloat(maxy*.1)]];      //  }       // not label max number, because label cut off @ top, looks bad     [exclusionranges addobject:[cptplotrange  plotrangewithlocation:cptdecimalfromfloat(maxy+1) length:cptdecimalfromfloat(99999)]];      yaxis.labelexclusionranges = exclusionranges;      // yaxis.title = @"mmhg";    }      // add annotation label daily goal.     // positioned @ left of graph, right of   axis, above 12am.     // @ position safe interference daily steps graph.     // not put on y labels, since automatically generated.     - (void)setupgoalannotation {       [self.graph.plotareaframe.plotarea removeallannotations];       nsnumber* dailygoal = 0;      if ([dailygoal intvalue] > 0) {       cptxyaxisset *axisset = (cptxyaxisset *)self.graph.axisset;      cptxyaxis *yaxis = axisset.yaxis;        // custom labels threshholds      cptmutabletextstyle* textstylethreshhold = [yaxis.labeltextstyle mutablecopy];      textstylethreshhold.fontname = klabelfontname;      textstylethreshhold.textalignment = cpttextalignmentcenter;      textstylethreshhold.fontsize = textstylethreshhold.fontsize - 4.0;       uiparam* uiparam = [uiparam shareduiparam];       cptborderedlayer* layerannotation = [graphutil borderedtextlayer:  [dailygoal description] style:textstylethreshhold margin:cgsizemake(4, 4)];      layerannotation.fill = [cptfill fillwithcolor:[cptcolor whitecolor]];      layerannotation.bordercolor = uiparam.colorgoalline.cgcolor;      layerannotation.borderwidth = 2.0;       cgfloat x = 0.0;       switch (self.data.dayinterval) {       case ymdayinterval1day:         x = 22.9;         break;        case ymdayinterval7day:         x = 6.60;         break;        case ymdayinterval14day:         x = 13.2;         break;        default:         break;     }       nsarray* anchorpoint = @[@(x), dailygoal ];      cptplotspaceannotation* annotation = [[cptplotspaceannotation alloc] initwithplotspace:self.graph.defaultplotspace anchorplotpoint:anchorpoint];     annotation.contentlayer = layerannotation;        [self.graph.plotareaframe.plotarea addannotation:annotation];     }   }      #pragma mark - cptplotdatasource delegate       - (nsuinteger)numberofrecordsforplot:(cptplot *)plot {         if (plot == self.plotgoal) {         return 2;     }      else {        if (self.data.dayinterval == ymdayinterval7day)         return 7;         return 14;     }  }       - (nsnumber *)numberforplot:(cptplot *)plot field:   (nsuinteger)fieldenum recordindex:(nsuinteger)idx {       if (plot == self.plotgoal) {         if (fieldenum == cptscatterplotfieldx) {           if (idx == 0)            return @(-1);         else            return @(9999);       }        else if (fieldenum == cptscatterplotfieldy) {         return 0;//self.data.stepssummary.dailystepsgoal.steps;       }     }      else {         if (fieldenum == cptbarplotfieldbarlocation) {         return @(idx);      }      else if (fieldenum == cptbarplotfieldbartip) {         nsdate* date = [self.data.startdate datebyaddingtimeinterval:  (seconds_per_day * idx)];          (ymbpseries* bpentry in self.data.bpseries) {          if ([bpentry.date isutcsameday:date]) {             if (bpentry.systolic > 0)               return @(bpentry.systolic);             else               return nil;          }        }      }    }     return nil;   }     @end 

image 1

you're on right track. use 1 plot space bar plot blood pressure , second plot space scatter plot of heart rate. set plotsymbol of scatter plot desired ellipse shape , fill , set datalinestyle nil. draw plot symbol @ each data point without connecting line between them.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -