【问题标题】:Getting the touch feedback on CPTXYGraph Pie Chart在 CPTXYGraph 饼图上获取触摸反馈
【发布时间】:2023-03-09 22:38:01
【问题描述】:

我正在使用 Core Plot 中的 CPTXYGraph 绘制饼图。我使用了委托方法

-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index

在单击饼图的特定切片时执行一些操作。但是当我触摸饼图时,我需要显示反馈或某种类型的图像更改,以表明特定切片被触摸,就像按钮事件一样。

是否有任何委托方法可以实现相同的目标。

【问题讨论】:

  • 您想提供什么样的反馈?更改所选切片的填充?分解选定的切片?添加标签或注释? Core Plot 可以做所有这些事情,但没有单一的“选择”指示。
  • 我只想给每个切片一个按钮类型的反馈。告诉用户他选择了哪个切片。
  • “按钮类型反馈”是什么意思?
  • 我的意思是,当我们触摸一个按钮时,它会改变颜色,用户可以通过这种颜色判断该操作已注册在按钮上。我正在寻找类似的东西。否则,用户可以通过该切片中的任何类型的更改来判断该饼的特定切片已被选中。

标签: ios core-plot


【解决方案1】:

会有一些工作要做。

首先,将此实现到饼图委托函数中。

-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index
{
    indexOfPieGraphPlot = index; //gives index of pie which is selected.
    isPieGraphPlot = YES;     //boolean. if set to yes, will call rootcontroller function which will add pop up.
}

然后在.h文件中添加CPTPlotSpaceDelegate

然后使用这个函数

- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point
{
    if(isPieGraphPlot) //if yes call showpopup of rootcontroller
    {
    isPieGraphPlot = NO;
    [rootController showPopUpView:point indexForPlot:indexOfPieGraphPlot];
    // point gives the x,y of the pie over which you want a pop up.
    }
    else    // if no then call remove popup from rootcontroller. this, incase user clicks anywhere else in graph.
    {
        [rootController removePopUp];
    }
    return  YES;
}

【讨论】:

  • 我已经在使用 -(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index 方法根据单击的切片填充表格视图。我想向用户指定他单击了特定切片。例如,当您单击一个按钮时,将有一个 ON 状态和一个 OFF 状态来指定他单击它的用户。饼图有实现吗?
【解决方案2】:

在您的数据源中实现-sliceFillForPieChart:recordIndex: 方法。跟踪所选切片(如果有)并使用它来决定对每个切片应用什么填充。在情节上致电-reloadData任何选择选择要强制它加载新的切片填充。

【讨论】:

  • 您能否告诉我如何为特定的选定切片添加渐变色...
  • 使用[CPTFill fillWithGradient:myGradient] 创建填充。请参阅CPTGradient docs 和 Core Plot 示例应用程序,详细了解您可以使用渐变进行哪些操作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多