簡體   English   中英

使用 Swift 5.0 隱藏 HIChart 餅圖的數據標簽

[英]Hide data labels of a HIChart's Pie chart using Swift 5.0

我正在使用 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

編輯:刪除 HIDataLabelsOptionsObject() 的最新 HICharts API (8.0.0) 中有一些更改,請參閱下面代碼中的更新答案。

這是我如何讓它工作的。 事實證明,您不需要 allowPointSelect、cursor 或 showInLegend 標志(盡管您可能希望保留 showInLegend 標志,因為您希望圖表上有圖例)來使其工作。 我真的不知道 allowPointSelect 或 cursor 做什么,因為您仍然可以點擊圖表並查看詳細信息。

plotoptions.pie = HIPie()
let dataLabel = HIDataLabels() // Older versions of API - HIDataLabelsOptionsObject()
dataLabel.enabled = false
plotoptions.pie.dataLabels = [dataLabel]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM