简体   繁体   English

iOS 使用多个数据集的图表 (MPAndroidChart) 始终显示“没有可用的图表数据”

[英]iOS Charts (MPAndroidChart) using multiple data sets always shows "No chart data available"

None of the solutions, in the multiple SO questions, for "No chart data available" is able to remove/modify the message:在多个 SO 问题中,“没有可用的图表数据”的解决方案都无法删除/修改消息:

MPAndroidchart No chart Data available MPAndroidchart 没有可用的图表数据

How to change the No Data message using iOS Charts? 如何使用 iOS 图表更改无数据消息?

collection view presentation of graph: "no chart data available" for Charts cocoapods 图表的集合视图表示:图表 cocoapods 的“没有可用的图表数据”

The chart displays the data correctly but also displays the message "No chart data available".图表正确显示数据,但也显示消息“没有可用的图表数据”。 It really just seems like a bug for the chart to have data but show this message.图表有数据但显示此消息似乎真的只是一个错误。

The only difference between the other SO questions and my problem is that I'm setting the data with dataSets instead of dataSet viz.其他 SO 问题与我的问题之间的唯一区别是我使用dataSets而不是dataSet即设置数据。 LineChartData(dataSets: data_sets) . LineChartData(dataSets: data_sets) Seeing this difference I tried creating the LineChart view with a dummy LineChartData initialized with dataSet , before running updateChartData() , but this didn't help either.看到这种差异,我尝试在运行updateChartData()之前使用用dataSet初始化的虚拟 LineChartData 创建 LineChart 视图,但这也无济于事。

I don't see a way to initialize the LineChartView with the data, the closest I've seen to potentially doing this is shown on this site我没有看到用数据初始化 LineChartView 的方法,我见过的最接近可能这样做的方法显示在此站点上

@IBOutlet weak var chartview_box: UIView!
var chartview: LineChartView 

override func viewDidLoad() {
    chartview = LineChartView()
    chartview.noDataText = "test"
    chartview.noDataTextColor = UIColor(hue: 0, saturation: 0, brightness: 0, alpha: 0)
    setChartOptions()
    updateChartData()
}

func updateChartData() {
    var data_sets: Array<LineChartDataSet> = []
    for frame in frames! {
        ... code setting x and y
        let entry = ChartDataEntry(x: x, y: y)
        let data_set = LineChartDataSet(entries: [entry])
        data_sets.append(data_set)
    }
    let data = LineChartData(dataSets: data_sets)
    chartview.data = data
}

This ended up being an issue with accidentally leaving a parent container as LineChartView when it should be UIView, so the parent view "behind" the chart was also a chart and displaying the message.这最终成为一个问题,当它应该是 UIView 时,意外地将父容器保留为 LineChartView,因此图表“后面”的父视图也是一个图表并显示消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM