使用Swift 5.0隐藏HIChart饼图的数据标签

时间:2019-06-24 16:00:50

标签: ios swift highcharts

我正在使用iOS-Swift 5.0中的HICharts库创建饼图

我不需要数据标签。只想要底部的图例。因此,我尝试使用下面的代码将其隐藏。

   let plotoptions = HIPlotOptions()  //Line 1
   plotoptions.pie = HIPie()         //Line 2
   plotoptions.pie.allowPointSelect =  NSNumber(value: true) //Line 3
   plotoptions.pie.cursor = "pointer"  //Line 4 
   plotoptions.pie.dataLabels = HIDataLabels()   //Line 5
   plotoptions.pie.dataLabels.enabled = NSNumber(value: false) //Line 6
   plotoptions.pie.showInLegend = true  //Line 7

但是我遇到了错误-

1. Cannot assign value of type 'HIDataLabels' to type '[HIDataLabelsOptionsObject]?'  at line number 5

2. Value of type '[HIDataLabelsOptionsObject]?' has no member 'enabled' at line number 6

我引用了用目标C编写的https://www.highcharts.com/ios/demo/pie-legend

1 个答案:

答案 0 :(得分:1)

这是我如何使它工作的。事实证明,您不需要allowPointSelect,cursor或showInLegend标志(尽管您可能希望保留showInLegend标志,因为您希望图表上有图例)才能使它起作用。我真的不知道allowPointSelect或游标的作用,因为您仍然可以点击图表并查看详细信息。

plotoptions.pie = HIPie()
let dataLabel = HIDataLabelsOptionsObject()
dataLabel.enabled = false
plotoptions.pie.dataLabels = [dataLabel]