简体   繁体   中英

LineChart with optional Y parameter swift

Require a LineChart where in it allows y value as nil . As when no data for that particular day( x ) is there the line should just go forward.

Currently I have researched on SwiftChart & Charts but both doesn't provide that functionality.

Please refer below image for more understanding.

在此处输入图像描述

As you can see Sunday, Monday & Wednesday there is data Tuesday there is no data so the line just continues from Monday to Wednesday.

How can I achieve this or if there is any library that can help me achieve this.

You can just skip some X value in https://github.com/danielgindi/Charts

在此处输入图像描述

private func setupChart() {
        let leftAxis = chart.leftAxis
        leftAxis.axisMinimum = 0
        leftAxis.axisMaximum = 100
        leftAxis.granularity = 10
        
        let rightAxis = chart.rightAxis
        rightAxis.enabled = false
        
        let xAxis = chart.xAxis
        xAxis.axisMinimum = 0
        xAxis.axisMaximum = 7
        xAxis.labelPosition = .bottom
        xAxis.granularity = 1
        
    }
    
    private func setupChartData() {
        var dataEntries: [ChartDataEntry] = []
        for i in 0...7 {
            if i % 2 == 0 {
                let value = arc4random_uniform(100) + 1
                if value != 0 {
                    let dataEntry = ChartDataEntry(x: Double(i), y: Double(value))
                    dataEntries.append(dataEntry)
                }
            }
        }
        let dataSet = LineChartDataSet(entries: dataEntries, label: "")
        let data = LineChartData(dataSet: dataSet)
        chart.data = data
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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