Ios Swift图表删除数据
我使用is-Charts,在UIView中我有按钮(1,2,3,4)和带图表的UIView 我希望如果按1键-删除旧数据行并用新数据显示新数据^Ios Swift图表删除数据,ios,swift,charts,Ios,Swift,Charts,我使用is-Charts,在UIView中我有按钮(1,2,3,4)和带图表的UIView 我希望如果按1键-删除旧数据行并用新数据显示新数据^ func populateData(withCount countA: [Double], countB: [Double]) { for index in 0..<countB.count{ let dataEntry = ChartDataEntry(x: countB[index], y: countA[inde
func populateData(withCount countA: [Double], countB: [Double]) {
for index in 0..<countB.count{
let dataEntry = ChartDataEntry(x: countB[index], y: countA[index])
values.append(dataEntry)
}
let set = LineChartDataSet(values: values, label: "")
set.mode = .cubicBezier
set.cubicIntensity = 0.2
set.drawCirclesEnabled = true
set.lineWidth = 2.7
set.circleRadius = 2.8
set.setCircleColor(.green)
set.setColor(#colorLiteral(red: 0.3176470588, green: 0.9960784314, blue: 0.6549019608, alpha: 1))
set.fillColor = .green
set.fillAlpha = 1.0
set.drawHorizontalHighlightIndicatorEnabled = false
set.drawVerticalHighlightIndicatorEnabled = false
let gradientColors = [UIColor.cyan.cgColor, UIColor.clear.cgColor] as CFArray
let colorLocations:[CGFloat] = [1.0, 0.0]
let gradient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: gradientColors, locations: colorLocations
set.fill = Fill.fillWithLinearGradient(gradient!, angle: 90.0)
set.drawFilledEnabled = true
let data = LineChartData(dataSet: set)
data.setDrawValues(false)
chartView.data = data
}
在按钮1中:
chartView.clear()
populateData(withCount: a, countB: b)
在按钮2中:
chartView.clear()
populateData(withCount: c, countB: d)
但它不起作用,数据不变,只添加和显示两行
如何删除和放置新数据?在填充数据之前,请执行以下操作:
values = []
顺便说一下,我会这样写:
func populateData(withCount countA: [Double], countB: [Double]) {
values = []
for index in 0..<countB.count{
let dataEntry = ChartDataEntry(x: countB[index], y: countA[index])
values.append(dataEntry)
}
...
func填充数据(使用count countA:[Double],countB:[Double]){
值=[]
对于0中的索引…非常感谢!
func populateData(withCount countA: [Double], countB: [Double]) {
values = []
for index in 0..<countB.count{
let dataEntry = ChartDataEntry(x: countB[index], y: countA[index])
values.append(dataEntry)
}
...