如何设置swift图表(折线图)中x轴线的绘制位置?
How to set where the x-axis line is drawn in swift charts (line chart)?
我在 iOS 应用程序中使用 swift 的图表。我目前将其设置在仅显示 x 轴线的位置,我想设置绘制 x 轴线的 y 值。为了说明这一点,我正在制作一张股票图表,并希望将 x 轴线设置为股票的第一个值(开盘价)。这是我当前的折线图视图。
编辑:现在线条总是绘制到视图的顶部。
let chartView: LineChartView = {
let view = LineChartView()
view.noDataText = ""
view.legend.enabled = false
view.legend.textColor = .clear
//X Axis
view.xAxis.wordWrapEnabled = true
view.xAxis.drawLabelsEnabled = false
view.xAxis.drawAxisLineEnabled = true
view.xAxis.axisLineColor = .white
view.xAxis.axisLineDashLengths = [2]
view.xAxis.drawGridLinesEnabled = false
//Y Axis
view.rightAxis.enabled = false
view.leftAxis.enabled = false
view.leftAxis.gridColor = .clear
view.rightAxis.gridColor = .clear
view.leftAxis.drawLabelsEnabled = false
view.leftAxis.axisMinimum = points[0] //HERE
return view
}()
我认为使用额外的数据集是在图表上绘制水平线的最简单方法。
var xMinValue: Double = 0 // use your own value
var xMaxValue: Double = 12 // use your own value
var yFirstValue: Double = 9 // set your open price
let horizontalLineDataEntries: [ChartDataEntry] = [
ChartDataEntry(x: xMinValue, y: yFirstValue),
ChartDataEntry(x: xMaxValue, y: yFirstValue)
]
let horizontalLineSataSet = LineChartDataSet(values: horizontalLineDataEntries, label: nil)
horizontalLineSataSet.setColor(.blue)
horizontalLineSataSet.lineWidth = 2
horizontalLineSataSet.drawCirclesEnabled = false
horizontalLineSataSet.drawValuesEnabled = false
chartData.addDataSet(horizontalLineSataSet)
chartView.data = chartData
我在 iOS 应用程序中使用 swift 的图表。我目前将其设置在仅显示 x 轴线的位置,我想设置绘制 x 轴线的 y 值。为了说明这一点,我正在制作一张股票图表,并希望将 x 轴线设置为股票的第一个值(开盘价)。这是我当前的折线图视图。
编辑:现在线条总是绘制到视图的顶部。
let chartView: LineChartView = {
let view = LineChartView()
view.noDataText = ""
view.legend.enabled = false
view.legend.textColor = .clear
//X Axis
view.xAxis.wordWrapEnabled = true
view.xAxis.drawLabelsEnabled = false
view.xAxis.drawAxisLineEnabled = true
view.xAxis.axisLineColor = .white
view.xAxis.axisLineDashLengths = [2]
view.xAxis.drawGridLinesEnabled = false
//Y Axis
view.rightAxis.enabled = false
view.leftAxis.enabled = false
view.leftAxis.gridColor = .clear
view.rightAxis.gridColor = .clear
view.leftAxis.drawLabelsEnabled = false
view.leftAxis.axisMinimum = points[0] //HERE
return view
}()
我认为使用额外的数据集是在图表上绘制水平线的最简单方法。
var xMinValue: Double = 0 // use your own value
var xMaxValue: Double = 12 // use your own value
var yFirstValue: Double = 9 // set your open price
let horizontalLineDataEntries: [ChartDataEntry] = [
ChartDataEntry(x: xMinValue, y: yFirstValue),
ChartDataEntry(x: xMaxValue, y: yFirstValue)
]
let horizontalLineSataSet = LineChartDataSet(values: horizontalLineDataEntries, label: nil)
horizontalLineSataSet.setColor(.blue)
horizontalLineSataSet.lineWidth = 2
horizontalLineSataSet.drawCirclesEnabled = false
horizontalLineSataSet.drawValuesEnabled = false
chartData.addDataSet(horizontalLineSataSet)
chartView.data = chartData