我正在尝试使用iOS图表库启用网格线,以最终实现类似这样的
到目前为止我的代码
func setChart(dataPoints:[String],values:[Double]){
var dataEntries: [ChartDataEntry] = []
let yAxis = lineChartView.getAxis(.Left)
let yAxisRight = lineChartView.getAxis(.Right)
let xAxis = lineChartView.xAxis
lineChartView.drawBordersEnabled = true
xAxis.spaceBetweenLabels = 1
xAxis.drawGridLinesEnabled = true
xAxis.gridLineWidth = 0.25
yAxisRight.enabled = false
yAxis.drawGridLinesEnabled = true
yAxis.axisMaxValue = 4.0
yAxis.axisMinValue = 1.0
yAxis.inverted = true
yAxis.setLabelCount(4, force: true)
yAxis.axisLineColor = UIColor.whiteColor()
var dataEntry = ChartDataEntry(value: 1.0, xIndex: 0)
dataEntries.append(dataEntry)
dataEntry = ChartDataEntry(value: 1.0, xIndex: 1)
dataEntries.append(dataEntry)
dataEntry = ChartDataEntry(value: 2.0, xIndex: 1)
dataEntries.append(dataEntry)
dataEntry = ChartDataEntry(value: 2.0, xIndex: 2)
dataEntries.append(dataEntry)
let lineChartDataSet = LineChartDataSet(yVals: dataEntries, label: "Units Sold")
let lineChartData = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)
lineChartView.data = lineChartData
}
//我的结果
网格线似乎没有绘制。非常感谢任何见解。
答案 0 :(得分:0)
您的网格线可能太薄 - 在分辨率较低的设备上,可能导致根本不显示线条。
iPhone 6或6 plus将显示0.25像素的线......但早期的设备不会。