objective c - CorePlot LineGraph - hover/ click on graph to see values - macOS -


i using coreplot plot simple line graph in macos app.

cptxygraph *newgraph = [[cptxygraph alloc] initwithframe:cgrectzero];  cpttheme *theme      = [cpttheme themenamed:kcptdarkgradienttheme]; [newgraph applytheme:theme]; self.graph = newgraph; self.hostview.hostedgraph = newgraph;  newgraph.plotareaframe.paddingtop   = 10.0; newgraph.plotareaframe.paddingbottom   = 30.0; newgraph.plotareaframe.paddingleft   = 40.0; newgraph.plotareaframe.paddingright  = 10.0;  cptxyplotspace *plotspace = (cptxyplotspace *)newgraph.defaultplotspace;     plotspace.xrange = [cptplotrange plotrangewithlocation:@(1.0) length:[nsnumber numberwithunsignedinteger:[dataarray count]-1]];     plotspace.yrange = [cptplotrange plotrangewithlocation:@0.0 length:@102.0];     plotspace.allowsuserinteraction = yes;  cptxyaxisset *axisset = (cptxyaxisset *)newgraph.axisset;     cptxyaxis *x          = axisset.xaxis;     //x.majorintervallength   = @1;     x.majorintervallength   = [nsnumber numberwithint:numberofintervalsx];     x.orthogonalposition    = @(0);     x.minorticksperinterval = 0;     x.labeloffset  = 0;      cptxyaxis *y = axisset.yaxis;     y.majorintervallength   = @5;     y.minorticksperinterval = 0;     y.orthogonalposition    = @(1.0);     y.labeloffset  = 0.0;  cptscatterplot *datasourcelineplot = [[cptscatterplot alloc] init];     cptmutablelinestyle *linestyle = [datasourcelineplot.datalinestyle mutablecopy];     linestyle.linewidth              = 2.;     linestyle.linecolor              = [cptcolor greencolor];     datasourcelineplot.datalinestyle = linestyle;       datasourcelineplot.datasource = self;     [newgraph addplot:datasourcelineplot]; 

i expecting hover/ click see values default behavior looks not. have tried searching forums no luck. assuming straight forward. not sure if missing something.

as far know, you're impression correct, there no built in data value overlay. however, can make yourself. coreplot has function indexofvisiblepointclosesttoplotareapoint: should give references needed add label w/ point value chart.

  • (nsuinteger) indexofvisiblepointclosesttoplotareapoint:

returns index of closest point, or nsnotfound if there no visible point.

then can subclass graph hostingview, implement mouse movement event capture mouse coordinates, , there whatever logic want chose how display points.

i wouldn't it's particularly easy implement, @ least straight foward. hope helps!

references:

http://core-plot.github.io/macos/interface_c_p_t_scatter_plot.html#a57eacc8261a4d4a1399f1196be786cff https://stackoverflow.com/a/21819342/357288


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -