Как установить набор данных линейного графика как отключенный при загрузке
Я использую платформы Charts (danielgindi / Charts).
Я хочу иметь lineChartView, который включает в себя 3 различных данныхкоторый может использовать кнопку, чтобы скрыть или показать их.
Например, нажатие кнопки 1 покажет / невидимый на lineChartView, но другие 2 различных данных по-прежнему отображаются.
class ViewController: UIViewController {
@IBOutlet weak var chartView: LineChartView!
var limitSet1 : ChartLimitLine?
var limitSet2 : ChartLimitLine?
var limitSet3 : ChartLimitLine?
var limitLineArray : [Double] = []
func removeLimitLines() {
switch (limitLineArray.count) {
case 1: print("there was 1 limit line, need to remove this from chart view")
chartView.rightAxis.removeLimitLine(limitSet1!)
case 2: print("there was 2 limit line, need to remove this from chart view")
chartView.rightAxis.removeLimitLine(limitSet1!)
chartView.rightAxis.removeLimitLine(limitSet2!)
case 3: print("there was 3 limit line, need to remove this from chart view")
chartView.rightAxis.removeLimitLine(limitSet1!)
chartView.rightAxis.removeLimitLine(limitSet2!)
chartView.rightAxis.removeLimitLine(limitSet3!)
default:
break
}
}
func setChart(xValues: [String], valuesLineChart: [[Double]], limitLines: [Double]) {
// chartView.descriptionText = ""
chartView.noDataText = "You need to provide data for the chart."
print("valuesLineChart has \(valuesLineChart.count) lines")
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
switch valuesLineChart.count {
case 1 : print("1 within switch")
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<xValues.count {
yVals1.append(ChartDataEntry(x: valuesLineChart[0][i], y: Double(i)))
}
let set1 = LineChartDataSet(entries: yVals1, label: nil)
dataSets.append(set1)
//limit lines
limitSet1 = ChartLimitLine(limit: limitLines[0], label: "switch1, limit1")
chartView.rightAxis.addLimitLine(limitSet1!)
case 2 :print("2 within switch")
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<xValues.count {
yVals1.append(ChartDataEntry(x: valuesLineChart[0][i], y: Double(i)))
}
var yVals2 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<xValues.count {
yVals2.append(ChartDataEntry(x: valuesLineChart[1][i], y: Double(i)))
}
let set1 = LineChartDataSet(entries: yVals1, label: nil)
let set2 = LineChartDataSet(entries: yVals2, label: nil)
dataSets.append(set1)
dataSets.append(set2)
//limit lines
limitSet1 = ChartLimitLine(limit: limitLines[0], label: "")
limitSet2 = ChartLimitLine(limit: limitLines[1], label: "")
chartView.rightAxis.addLimitLine(limitSet1!)
chartView.rightAxis.addLimitLine(limitSet2!)
case 3 :print("3 within switch")
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<xValues.count {
yVals1.append(ChartDataEntry(x: valuesLineChart[0][i], y: Double(i)))
}
var yVals2 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<xValues.count {
yVals2.append(ChartDataEntry(x: valuesLineChart[1][i], y: Double(i)))
}
var yVals3 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0..<xValues.count {
yVals3.append(ChartDataEntry(x: valuesLineChart[2][i], y: Double(i)))
}
let set1 = LineChartDataSet(entries: yVals1, label: nil)
let set2 = LineChartDataSet(entries: yVals2, label: nil)
let set3 = LineChartDataSet(entries: yVals3, label: nil)
dataSets.append(set1)
dataSets.append(set2)
dataSets.append(set3)
//limit lines
limitSet1 = ChartLimitLine(limit: limitLines[0], label: "")
limitSet2 = ChartLimitLine(limit: limitLines[1], label: "")
limitSet3 = ChartLimitLine(limit: limitLines[2], label: "")
chartView.rightAxis.addLimitLine(limitSet1!)
chartView.rightAxis.addLimitLine(limitSet2!)
chartView.rightAxis.addLimitLine(limitSet3!)
default:
break
}
let chartData = LineChartData( dataSets: dataSets)
chartView.data = chartData
}