作者:mobiledu2502925915 | 来源:互联网 | 2023-02-13 12:20
您好开发人员我正在开发项目,我已经使用了danielgindi/Charts第三方库,现在我面临的挑战是我需要提供一个跟踪球,如图中最高点的图像所示.如何才能实现这一点? ?或者如何访问BarChart上方的值,我想在最高峰(20.0)上打印其他内容,如"E"?
1> Harshit Goel..:
不幸的是,没有办法在条形图上方的值处设置图像而不是String或Double.但是,我们可以访问上面的值,请访问提到的链接.
https://github.com/danielgindi/Charts/issues/2126
class ViewController: UIViewController {
var chartData = BarChartData()
var months: [String]!
var unitsSold = [Double]()
weak var valueFormatter: IValueFormatter?
@IBOutlet var viewForChart: BarChartView!
override func viewDidLoad() {
super.viewDidLoad()
valueFormatter = self
mOnths= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]
setChart(dataEntryX: months, dataEntryY: unitsSold)
}
func setChart(dataEntryX forX:[String],dataEntryY forY: [Double]) {
viewForChart.noDataText = "You need to provide data for the chart."
var dataEntries:[BarChartDataEntry] = []
for i in 0..
在类之上或之外添加扩展名
extension ViewController: IValueFormatter {
func stringForValue(_ value: Double, entry: ChartDataEntry, dataSetIndex: Int, viewPortHandler: ViewPortHandler?) -> String {
print(value)
//logic to print string at required point or value
switch value {
case 20.0: return ""
default: return ""
}
}
}