我已经制作了一个小应用程序,用于从iWatch测量心率。该图表按预期工作,显示了当前的心律,但是我在设计中遇到了几个问题。在下面,您可以迅速找到图表的图像及其设置。
//chart set up
self.chtChart.delegate = self as? ChartViewDelegate
self.chtChart.noDataTextColor = UIColor.white
self.chtChart.noDataText = "Press Start button to display the chart"
let set_a: LineChartDataSet = LineChartDataSet(entries:[ChartDataEntry(x: Double(Int(0)), y: self.valueHR)], label: "BPM")
set_a.drawCirclesEnabled = false
set_a.setColor(UIColor.systemPink)
set_a.drawValuesEnabled = false
set_a.lineWidth = 5.0
//remove vertical grid and labels
self.chtChart.xAxis.drawGridLinesEnabled = false
self.chtChart.rightAxis.drawLabelsEnabled = false
self.chtChart.xAxis.drawLabelsEnabled = false
//change label 'BPM' color
self.chtChart.legend.textColor = UIColor.white
//change left numbers (bpm values)
self.chtChart.leftAxis.labelTextColor = UIColor.white
//change right border line color
self.chtChart.rightAxis.axisLineColor = UIColor.white
//change left border line to white
self.chtChart.leftAxis.axisLineColor = UIColor.white
//change values from decimal to int on left axis
let fmt = NumberFormatter()
fmt.numberStyle = .decimal
fmt.maximumFractionDigits = 0
fmt.groupingSeparator = ","
fmt.decimalSeparator = "."
self.chtChart.leftAxis.valueFormatter = DefaultAxisValueFormatter.init(formatter: fmt)
self.chtChart.data = LineChartData(dataSets: [set_a])
如您所见,我的图表没有底部边框,我也无法更改图表内部的网格线的颜色(我想将其更改为白色)。我尝试了以下命令,但未更改任何内容:
self.chtChart.xAxis.axisLineColor = UIColor.white
self.chtChart.borderColor = UIColor.white
self.chtChart.xAxis.gridColor = UIColor.white
答案 0 :(得分:1)
我浏览了所有可能的属性,发现添加了以下行:
self.chtChart.xAxis.axisLineColor = UIColor.white
self.chtChart.rightAxis.gridColor = UIColor.white
解决了底部边框的问题,并将网格线的颜色更改为白色。
编辑:最根本的问题似乎仍然是一个问题。它不会显示在屏幕上。
Edit2:一次添加所有边框并设置其颜色似乎可以解决此问题:
self.chtChart.drawBordersEnabled = true
self.chtChart.borderColor = UIColor.white