当图表上没有数据图时图表视口高度增加
Chart viewport height increase when chart has no data plot on chart
我正在使用 https://github.com/danielgindi/Charts 库。当图表没有数据时,图表高度增加应该与图表有数据时相同。图表 xAxis 标签与字符标题重叠。任何帮助,将不胜感激。图表设置代码
var dataEntries: [ChartDataEntry] = []
axisFormatDelegate = self
chartView.legend.form = .none
let rightAxis = chartView.rightAxis
rightAxis.enabled = false
let yAxis = chartView.leftAxis
let xAxisValue = chartView.xAxis
xAxisValue.valueFormatter = axisFormatDelegate
xAxisValue.axisMinimum = -1
xAxisValue.axisMaximum = Double(forX.count)
xAxisValue.granularity = 1
for i in 0..<forX.count {
if forY[i] != 0 {
let dataEntry = ChartDataEntry(x: Double(i), y: forY[i])
dataEntries.append(dataEntry)
}
}
let lineChartDataSet = LineChartDataSet(entries: dataEntries, label: "")
let lineChartData = LineChartData(dataSet: lineChartDataSet)
print("Line chart data: \(lineChartData.dataSets)")
chartView.data = lineChartData
包含数据的图表:
没有数据的图表:
我认为是因为您将 legend.form 设置为 .none,它没有显示图例,但仍然有 space
我通常用它来隐藏图例并在 xAxis 标签底部使用额外的边距
chartView.legend.enabled = false
chartView.extraBottomOffset = 10
我正在使用 https://github.com/danielgindi/Charts 库。当图表没有数据时,图表高度增加应该与图表有数据时相同。图表 xAxis 标签与字符标题重叠。任何帮助,将不胜感激。图表设置代码
var dataEntries: [ChartDataEntry] = []
axisFormatDelegate = self
chartView.legend.form = .none
let rightAxis = chartView.rightAxis
rightAxis.enabled = false
let yAxis = chartView.leftAxis
let xAxisValue = chartView.xAxis
xAxisValue.valueFormatter = axisFormatDelegate
xAxisValue.axisMinimum = -1
xAxisValue.axisMaximum = Double(forX.count)
xAxisValue.granularity = 1
for i in 0..<forX.count {
if forY[i] != 0 {
let dataEntry = ChartDataEntry(x: Double(i), y: forY[i])
dataEntries.append(dataEntry)
}
}
let lineChartDataSet = LineChartDataSet(entries: dataEntries, label: "")
let lineChartData = LineChartData(dataSet: lineChartDataSet)
print("Line chart data: \(lineChartData.dataSets)")
chartView.data = lineChartData
包含数据的图表:
没有数据的图表:
我认为是因为您将 legend.form 设置为 .none,它没有显示图例,但仍然有 space
我通常用它来隐藏图例并在 xAxis 标签底部使用额外的边距
chartView.legend.enabled = false
chartView.extraBottomOffset = 10