Chart viewport height increase when chart has no data plot on chart

眉间皱痕 提交于 2020-07-23 06:16:35

问题


I am using https://github.com/danielgindi/Charts library. When the chart has no data then chart height increased it should be the same as when the chart has data. Chart xAxis labels overlapped with char title. Any help would be appreciated. Code for chart setup

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
        

The chart with data:

The chart with no data:


回答1:


I think it because you set legend.form to .none, it not showing legend but still had space for it

I usually use this to hide legend and to give extra margin in bottom of xAxis label use

chartView.legend.enabled = false
chartView.extraBottomOffset = 10


来源:https://stackoverflow.com/questions/62830642/chart-viewport-height-increase-when-chart-has-no-data-plot-on-chart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!