我正在处理多轴图表。我在相同的轴上添加了两个具有不同颜色的样条曲线,但该线以相同的颜色显示,并且彼此联接。看到图片
我的代码是:
class ViewController: UIViewController {
@IBOutlet var chartView: HIChartView!
var xAxisData = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
var spline1Data = [3, 4, 3, 5, 4, 10, 12]
var spline2Data = [1, 3, 4, 3, 3, 5, 4]
struct Area {
static var isAreaOne = true
static var isAreaTwo = true
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
initChart()
}
func initChart() {
let options = HIOptions()
let chart = HIChart()
chart.type = "areaspline"
let title = HITitle()
title.text = ""
let xaxis = HIXAxis()
xaxis.categories = xAxisData
let yaxis = HIYAxis()
yaxis.title = HITitle()
yaxis.title.text = ""
let tooltip = HITooltip()
tooltip.shared = 1
tooltip.valueSuffix = " units"
let credits = HICredits()
credits.enabled = 0
let exporting = HIExporting()
exporting.enabled = false
let plotoptions = HIPlotOptions()
plotoptions.areaspline = HIAreaspline()
plotoptions.areaspline.fillOpacity = 0.5
plotoptions.areaspline.dataLabels = HIDataLabels()
plotoptions.areaspline.dataLabels.enabled = true
let areaspline1 = HIAreaspline()
areaspline1.name = "John"
areaspline1.data = spline1Data
let areaspline2 = HIAreaspline()
areaspline2.name = "Jane"
areaspline2.data = spline2Data
options.chart = chart
options.title = title
options.xAxis = [xaxis]
options.yAxis = [yaxis]
options.tooltip = tooltip
options.credits = credits
options.exporting = exporting
options.plotOptions = plotoptions
if Area.isAreaOne && Area.isAreaTwo {
options.series = [areaspline1, areaspline2]
}else if Area.isAreaOne {
options.series = [areaspline1]
}else if Area.isAreaTwo {
options.series = [areaspline2]
}else {
options.series = []
}
chartView.options = options
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnOneDidClicked(_ sender: UIButton) {
Area.isAreaOne = !Area.isAreaOne
initChart()
}
@IBAction func btn2DidClicked(_ sender: UIButton) {
Area.isAreaTwo = !Area.isAreaTwo
initChart()
}
}
为什么在多轴图表上会发生这种情况? 请帮助