'How to update graph data with send action button
I have implemented a graph in my Dashboard but I can't change the data.
the @IBAction func euroANDm3Click is a button which should change the data according to the unit euro, but that is not working.
I have no idea why uniteuro = uniteuros is not changing the data and then updating the graph when the button is touched?
@IBAction func euroANDm3Click(_ sender: Any) {
euroANDm3.addTarget(self, action: #selector(changeValue), for: .touchUpInside)
}
@objc func changeValue() {
uniteuro = uniteuros
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]
uniteuros = [13,24,42,59,36,63,55,79,51,35,38,44]
setChartforEUR(dataPoints: months, values: uniteuro)
}
func setChartforEUR(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
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
