如何在触摸按钮时更新图表视图
我有一个图表,显示每个蜡烛和 m3 蜡烛的欧元价格,所以我想在用户触摸按钮时更改它,例如如果它是欧元,则将其更改为 m3
使用的库:danielgindi/Charts
所以在下面的图表图像中:
- 用户单击按钮,
- 数据需要从 EURO 更改为 m3,
- 标签需要从 EURO 更改为 m3。
到目前为止实现的代码:
extension dashboardViewController: AxisValueFormatter {
AxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
print(Int(value))
return months[Int(value)]
}
}
@IBAction func euroANDm3(_ sender: Any) {
euroANDm3.addTarget(self, action: #selector(changeValue), for: .touchUpInside)
}
@objc func changeValue() {
uniteuro = uniteurotest
barChart.reloadInputViews()
}
override func viewDidLayoutSubviews() {
super.viewDidLoad()
axisFormatDelegate = self
months = ["Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
uniteuro = [43,34,52,39,36,33,55,39,51,45,38,44]
uniteurotest = [41,41,41,41,41,41,41,39,51,45,38,44]
setChart(dataPoints: months, values: uniteuro)
}
func setChart(dataPoints: [String], values: [Double]) {
barChart.noDataText = "NO DATA"
var dataEntries = [BarChartDataEntry]()
for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: values[i], data: dataPoints)
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(entries: dataEntries, label: "EUR")
let chartData = BarChartData(dataSet: chartDataSet)
barChart.data = chartData
barChart.xAxis.valueFormatter = axisFormatDelegate
}
I have a Chart that shows the Euro price for each candle and m3 candles, so I want to change it when the user touch the button for example if its in EURO to change it to m3
Library used: danielgindi/Charts
so at chartImage below:
- the user clicks the button
- the data needs to change from EURO to m3 and
- the label needs to change from EURO to m3.
The code implemented so far:
extension dashboardViewController: AxisValueFormatter {
AxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
print(Int(value))
return months[Int(value)]
}
}
@IBAction func euroANDm3(_ sender: Any) {
euroANDm3.addTarget(self, action: #selector(changeValue), for: .touchUpInside)
}
@objc func changeValue() {
uniteuro = uniteurotest
barChart.reloadInputViews()
}
override func viewDidLayoutSubviews() {
super.viewDidLoad()
axisFormatDelegate = self
months = ["Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
uniteuro = [43,34,52,39,36,33,55,39,51,45,38,44]
uniteurotest = [41,41,41,41,41,41,41,39,51,45,38,44]
setChart(dataPoints: months, values: uniteuro)
}
func setChart(dataPoints: [String], values: [Double]) {
barChart.noDataText = "NO DATA"
var dataEntries = [BarChartDataEntry]()
for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: values[i], data: dataPoints)
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(entries: dataEntries, label: "EUR")
let chartData = BarChartData(dataSet: chartDataSet)
barChart.data = chartData
barChart.xAxis.valueFormatter = axisFormatDelegate
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论