首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CorePlot LineGraph -悬停/单击图形以查看值- macOS

CorePlot LineGraph -悬停/单击图形以查看值- macOS
EN

Stack Overflow用户
提问于 2017-09-12 21:35:21
回答 1查看 132关注 0票数 9

我在我的macOS应用程序中使用CorePlot绘制了一个简单的折线图。

代码语言:javascript
复制
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];

我本以为悬停/单击查看值将是默认行为,但看起来不是。我试着在论坛上搜索,但没有成功。我假设这将是非常直接的。不知道我是不是漏掉了什么。

EN

回答 1

Stack Overflow用户

发布于 2017-09-19 18:11:12

据我所知,你的印象是正确的,没有内置的数据值覆盖。不过,你也可以自己做。CorePlot有一个函数indexOfVisiblePointClosestToPlotAreaPoint:,它可以为您提供在图表中添加带有点值的标签所需的参考。

  • (NSUInteger) indexOfVisiblePointClosestToPlotAreaPoint:

返回最近点的索引,如果没有可见点,则返回NSNotFound。

然后你可以子类化你的图形主机视图,实现一个鼠标移动事件来捕捉鼠标坐标,并从那里做任何你想要的逻辑来选择如何显示点。

我不会说它特别容易实现,但至少它是直接向前的。我希望它能有所帮助!

参考文献:

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46177890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档