ChartsOrg / ChartsOrg/Charts

removeDataSet(dataSet1) is not working

Open
#4,232 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

When i tapped button the chartView will be shown the dataset when i clicked(addDataSet), -< is okay but when i tapped twice (removeDataSet)is not working. the chartView still appear the old dataset and adding the new dataSet.

var tapped: Bool = false
let chartDataSet1 = LineChartDataSet()
let chartData = LineChartData()

@IBAction func firstBtn(_ sender: Any) {

var dataEntries1 = [ChartDataEntry]()
for i in 0..<100 {
let y = arc4random()%60
let entry = ChartDataEntry.init(x: Double(i), y: Double(y))
dataEntries1.append(entry)
}
let chartDataSet1 = LineChartDataSet(entries: dataEntries1, label: nil)
chartDataSet1.colors = [.black]

if tapped{
chartView.data?.removeDataSet(chartDataSet1)
chartView.data?.notifyDataChanged()
chartView.notifyDataSetChanged()
tapped = false

}else {
chartView.data?.notifyDataChanged()
chartView.notifyDataSetChanged()
chartView.data?.addDataSet(chartDataSet1)

tapped = true
}
}
viewDidLoad
let chartData = LineChartData(dataSets: [chartDataSet1]
chartView.data = chartData

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.