如何使用iOS图表更改无数据消息



当使用iOS图表并且没有数据时,会有一条默认消息,上面写着"没有可用的图表数据";。这个默认值可以编辑和处理翻译吗?

这是在显示数据之前自定义图表外观的方法。

@IBOutlet private weak var chart: LineChartView!
chart.noDataText = "Loading"
chart.noDataTextColor = .green
chart.noDataFont = UIFont(name: "Helvetica", size: 10.0)!

FYI我在表视图单元格中使用图表,发现我需要在wakeFromNib((中设置各种noData参数,以便正确反映它们。

override func awakeFromNib() {
//show the activity indicator which automatically animates
activityIndicator.isHidden = false

projectionChartView.noDataText = "Loading..."
projectionChartView.noDataFont = UIFont.systemFont(ofSize: 18.0, weight: .medium)
}

您可以使用.noDataText沿着以下行的行编辑默认值:

lazy var lineChartView: LineChartView = {
let chartView = LineChartView()
chartView.noDataText = NSLocalizedString("chart_no_data", comment: "")
...

return chartView
}()

最新更新