gpt4 book ai didi

ios - 如何使用 Daniel Gindis 图表库在同一轴上绘制相同类型的图表(在折线图中)?

转载 作者:行者123 更新时间:2023-11-28 05:38:50 25 4
gpt4 key购买 nike

我有一个图表,可以在同一轴上显示多个折线图和散点图。它们都将具有相同的 x 轴。我似乎不能在同一轴内放置多个折线图。

我已经尝试实现 CombinedChartView。我创建了一个函数,该函数接收相应数据集的数组。

    func customiseChart (rule1x: [Double], rule1y: [Double], rule2x: [Double], rule2y: [Double], rule3x: [Double], rule3y: [Double], rule4x: [Double], rule4y: [Double], rule5x: [Double], rule5y: [Double], rule6x: [Double], rule6y: [Double], rule7x: [Double], rule7y: [Double], suppressedSparksX: [Double], suppressedSparksY: [Double], exsuppressedSparksX: [Double], exsuppressedSparksY: [Double], CombinedChartView: CombinedChartView, labelRule1: String, labelRule2: String, labelRule3: String, labelRule4: String, labelRule5: String, labelRule6: String, labelRule7: String, labelSuppressed: String, labelExsuppressed: String)  {

//1) set ChartDataEntry for all the graphs
var rule1ChartEntries: [ChartDataEntry] = []
for i in 0..<rule1y.count {
let entries = ChartDataEntry(x: rule1x[i], y: rule1y[i])
rule1ChartEntries.append(entries)
}

. . .

var rule7ChartEntries: [ChartDataEntry] = []
for i in 0..<rule7y.count {
let entries = ChartDataEntry(x: rule7x[i], y: rule7y[i])
rule7ChartEntries.append(entries)
}
var suppressedScatterChartEntries: [ChartDataEntry] = []
for i in 0..<suppressedSparksY.count {
let entries = ChartDataEntry(x: suppressedSparksX[i], y: suppressedSparksY[i])
suppressedScatterChartEntries.append(entries)
}
var exsuppressedScatterChartEntries: [ChartDataEntry] = []
for i in 0..<exsuppressedSparksY.count {
let entries = ChartDataEntry(x: exsuppressedSparksX[i], y: exsuppressedSparksY[i])
exsuppressedScatterChartEntries.append(entries)
}

//2) set ChartDataSet for all the charts
let rule1DataSet = LineChartDataSet(entries: rule1ChartEntries, label: labelRule1)
rule1DataSet.colors = [NSUIColor.black]
let rule1data = LineChartData()
rule1data.addDataSet(rule1DataSet)
rule1DataSet.drawCirclesEnabled = false
rule1DataSet.drawValuesEnabled = false

let rule2DataSet = LineChartDataSet(entries: rule2ChartEntries, label: labelRule2)
rule2DataSet.colors = [NSUIColor.darkGray]
let rule2data = LineChartData()
rule2data.addDataSet(rule2DataSet)
rule2DataSet.drawCirclesEnabled = false
rule2DataSet.drawValuesEnabled = false

. . .

let rule7DataSet = LineChartDataSet(entries: rule7ChartEntries, label: labelRule7)
rule7DataSet.colors = [NSUIColor.yellow]
let rule7data = LineChartData()
rule7data.addDataSet(rule7DataSet)
rule7DataSet.drawCirclesEnabled = false
rule7DataSet.drawValuesEnabled = false

let suppressedSparkDataSet = ScatterChartDataSet(entries: suppressedScatterChartEntries, label: labelSuppressed)
suppressedSparkDataSet.colors = [NSUIColor.red]
let suppressedData = ScatterChartData()
suppressedData.addDataSet(suppressedSparkDataSet)

let exsuppressedSparkDataSet = ScatterChartDataSet(entries: exsuppressedScatterChartEntries, label: labelExsuppressed)
exsuppressedSparkDataSet.colors = [NSUIColor.blue]
let exsuppressedData = ScatterChartData()
exsuppressedData.addDataSet(exsuppressedSparkDataSet)

// 3) set combinedData
let combinedData = CombinedChartData()
combinedData.lineData = rule1data
combinedData.lineData = rule2data
combinedData.lineData = rule3data
combinedData.lineData = rule4data
combinedData.lineData = rule5data
combinedData.lineData = rule6data
combinedData.lineData = rule7data

combinedData.scatterData = suppressedData
combinedData.scatterData = exsuppressedData

//4) assign all the data into the combined chart
CombinedChartView.data = combinedData

}

我想让所有的图表都显示在图表上。但是,只显示最后声明的 lineChart 和 ScatterChart,即图表上只有 rule7data 和 exsuppressedData。图表的其余部分不显示。

最佳答案

而不是这样做

    let rule1data = LineChartData()
rule1data.addDataSet(rule1DataSet)

您可以将多个数据集添加到一个 LineChartData

所以你可以这样做:

let allLineDatas = LineChartData(dataSets: [rule1DataSet, rule2DataSet,....])


combinedData.lineData = allLineDatas

其他人也一样。

combinedData.scatterData = allScatterDatas

你可以下载他们的sample project并在模拟器中运行,你会在那里找到各种例子,然后你可以找到你需要集成的例子的代码

关于ios - 如何使用 Daniel Gindis 图表库在同一轴上绘制相同类型的图表(在折线图中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57671313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com