我在 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
我提到了https://www.highcharts.com/ios/demo/pie-legend这是用 Objective C 写的。
最佳答案
编辑:最新的 HICharts API (8.0.0) 中有一些更改删除了 HIDataLabelsOptionsObject(),请参阅下面代码中的更新答案。
下面是我如何让它工作的。事实证明,您不需要 allowPointSelect、cursor 或 showInLegend 标志(尽管您可能希望保留 showInLegend 标志,因为您希望在图表上显示图例)来使其工作。我真的不知道 allowPointSelect 或 cursor 的作用,因为您仍然可以点击图表并查看详细信息。
plotoptions.pie = HIPie()
let dataLabel = HIDataLabels() // Older versions of API - HIDataLabelsOptionsObject()
dataLabel.enabled = false
plotoptions.pie.dataLabels = [dataLabel]
关于ios - 使用 Swift 5.0 隐藏 HIChart 饼图的数据标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56740243/