Я использую Горизонтальную гистограмму, и все мои значения находятся в диапазоне от 10 до 30.
Я хочу отобразить значения на графике, однако drawValuesEnabled зависит от maxVisibleCount (из источника iOS-диаграмм)
Из BaseDataSet.swift
/// Set this to true to draw y-values on the chart.
///
/// - note: For bar and line charts: if `maxVisibleCount` is reached, no values will be drawn even if this is enabled.
open var drawValuesEnabled = true
Я вижу, что maxVisibleCount по умолчанию установлено в BarLineChartViewBase.swift как 100.
Я попытался установить maxVisibleCount в 5 в BarLineChartViewBase.swift.
Это не обновляет график.
Я использую Pod для использования диаграмм iOS в моем проекте.
Настройки диаграммы:
chartDataSet.drawValuesEnabled = true
chartDataSet.drawIconsEnabled = true
chartDataSet.visible = true
chartDataSet.colors = barColors
let data = BarChartData(dataSet: chartDataSet)
let formatter = NumberFormatter()
formatter.numberStyle = .none
formatter.maximumFractionDigits = 0
formatter.multiplier = 1.0
data.setValueFormatter(DefaultValueFormatter(formatter: formatter))
data.setDrawValues(true)
let xaxis = hBarChart.xAxis
xaxis.labelCount = 24
xaxis.valueFormatter = IndexAxisValueFormatter(values:hours)
xaxis.granularity = 1
xaxis.labelPosition = .bottom
xaxis.drawAxisLineEnabled = false
xaxis.drawGridLinesEnabled = false
xaxis.labelTextColor = .darkGray
let gridColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 0.8)
let yaxis = hBarChart.leftAxis
yaxis.drawGridLinesEnabled = true
yaxis.gridColor = gridColor
yaxis.enabled = true
yaxis.labelPosition = .insideChart
yaxis.labelTextColor = .darkGray
hBarChart.rightAxis.enabled = true
hBarChart.rightAxis.gridColor = gridColor
hBarChart.backgroundColor = .white
hBarChart.translatesAutoresizingMaskIntoConstraints = false
hBarChart.setVisibleYRangeMaximum(5, axis: .left)
hBarChart.setVisibleXRangeMaximum(5)
hBarChart.drawMarkers = true
hBarChart.extraTopOffset = 20
hBarChart.extraBottomOffset = 20
hBarChart.isUserInteractionEnabled = false
hBarChart.drawValueAboveBarEnabled = true
hBarChart.chartDescription?.text = "SDN Trend"
hBarChart.animate(yAxisDuration: 1, easingOption: .easeOutBounce)
hBarChart.legend.enabled = false