【问题标题】:Core-Plot Mac: show label when mouseover point in graphCore-Plot Mac:当鼠标悬停在图表中时显示标签
【发布时间】:2012-02-27 12:53:59
【问题描述】:

我正在构建一个 mac osx 应用程序,其中包含一个使用 Core-Plot 制作的漂亮图表。它是一个折线图(散点图),上面有多个点,用 plotsymbol 圆可视化。 我的目标是在用户将鼠标悬停在图表中的某个点上时显示一个带有该点值的标签。

我已经在图表中添加了 NSTracking,这很有效,但是我不知道如何将绘图点/绘图符号转换为坐标,所以我知道它何时翻转一个点并显示一个标签。

有人有想法吗? 谢谢大家

【问题讨论】:

    标签: macos core-plot


    【解决方案1】:

    我的解决方案是这样的:

    (我假设图表不显示任何标签。仅当鼠标悬停在图表上的某个点上时才会显示标签。)

    在你处理鼠标逻辑的地方,你会这样做:

        NSDecimalNumber *tickLocation = [NSDecimalNumber numberWithDouble:"The relevant axis value of the object you have the mouse over"];
        NSString *labelText = @"The text of the label";
        NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:1];
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText: labelText textStyle:axisSet."Whatever axis you want -X/Y".labelTextStyle];
        label.tickLocation = [tickLocation decimalValue];
        label.offset = axisSet."Whatever axis you want -X/Y".labelOffset + axisSet."Whatever axis you want -X/Y".majorTickLength;
        label.rotation = M_PI/4;
        [customLabels addObject:label];
        axisSet."Whatever axis you want -X/Y".axisLabels =  [NSSet setWithArray:customLabels];
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      您可以使用-indexOfVisiblePointClosestToPlotAreaPoint: 方法找出最接近某个像素的绘图符号。该方法返回该点的数据源索引;您可以查看数据源提供的原始数据以获取实际值。 plotSymbolMarginForHitDetection 属性控制点在注册为命中之前必须与给定点的距离。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多