iphone - Core Plot generating a flat line, X or Y range incorrect? -
i using core plot plot 2000 data points. load fine, see smooth line:
i not sure why flat line rather showing graph of of values in large range. have done wrong setting plot space?
cpxyplotspace *plotspace = (cpxyplotspace *)graph.defaultplotspace; plotspace.allowsuserinteraction = no; plotspace.xrange = [cpplotrange plotrangewithlocation:cpdecimalfromfloat(0.0) length:cpdecimalfromfloat(num_points)]; plotspace.yrange = [cpplotrange plotrangewithlocation:cpdecimalfromfloat(0.0) length:cpdecimalfromfloat(num_points)];
here numberforplot method well:
-(nsnumber *)numberforplot:(cpplot *)plot field:(nsuinteger)fieldenum recordindex:(nsuinteger)index { nsnumber *num = [sortedarray objectatindex:index]; return num; }
any ideas doing wrong here?
there couple of different issues here:
the plot space ranges given in data coordinates. can either calculate ranges or use plot space method
-scaletofitplots:
calculate them automatically. see answer your related question on core plot discussion board how calculate ranges manually.your
-numberforplot:field:recordindex:
ignores field parameter. you're returning same value both cpscatterplotfieldx , cpscatterplotfieldy, hence diagonal line.
one possible solution:
-(nsnumber *)numberforplot:(cpplot *)plot field:(nsuinteger)fieldenum recordindex:(nsuinteger)index { nsnumber *num = nil; switch ( fieldenum ) { case cpscatterplotfieldx: num = [nsnumber numberwithunsignedinteger:index]; break; case cpscatterplotfieldy: num = [sortedarray objectatindex:index]; break; } return num; }
eric
Comments
Post a Comment