ios-chart值不会基于x和y轴Swift绘制

问题描述 投票:1回答:1

我正在Swift 4中实现ios-chart。这是我的代码。

for loopValue in details {
        if let datetime = loopValue["datetime"]?.rawString(), let tempValue: Double = loopValue["temperature"]?.double {
            if let haveDate = DateFormatter.defaultAPIDateFormatter().date(from: datetime) {
                print("(\(haveDate), \(Double(haveDate.timeIntervalSince1970))\nY: \(tempValue))")
                let timeInterVel = Double(haveDate.timeIntervalSince1970)
                xyValues.append(ChartDataEntry(x: timeInterVel, y: tempValue))
            }
        }
    }

也尝试了直接的价值,太工作了

let xyValues: [ChartDataEntry] = [ChartDataEntry.init(x: 1511360172.0, y: 59.13), ChartDataEntry.init(x: 1511360112.0, y: 59.13), ChartDataEntry.init(x: 1511360051.0, y: 59.13), ChartDataEntry.init(x: 1511359991.0, y: 59.13), ChartDataEntry.init(x: 1511359931.0, y: 59.13), ChartDataEntry.init(x: 1511359871.0, y: 59.13), ChartDataEntry.init(x: 1511359810.0, y: 59.13), ChartDataEntry.init(x: 1511359750.0, y: 59.13), ChartDataEntry.init(x: 1511359690.0, y: 59.13)]

我的x和y轴值示例日志

(2017-11-22 14:16:12 +0000, 1511360172.0
Y: 59.13)
(2017-11-22 14:15:12 +0000, 1511360112.0
Y: 59.13)
(2017-11-22 14:14:11 +0000, 1511360051.0
Y: 59.13)
(2017-11-22 14:13:11 +0000, 1511359991.0
Y: 59.13)
(2017-11-22 14:12:11 +0000, 1511359931.0
Y: 59.13)
(2017-11-22 14:11:11 +0000, 1511359871.0
Y: 59.13)
(2017-11-22 14:10:10 +0000, 1511359810.0
Y: 59.13)
(2017-11-22 14:09:10 +0000, 1511359750.0
Y: 59.13)
(2017-11-22 14:08:10 +0000, 1511359690.0
Y: 59.13)
(2017-11-22 14:07:10 +0000, 1511359630.0
Y: 59.13)
(2017-11-22 14:06:09 +0000, 1511359569.0
Y: 59.13)
(2017-11-22 14:05:09 +0000, 1511359509.0
Y: 59.13)
(2017-11-22 14:04:09 +0000, 1511359449.0
Y: 59.13)

enter image description here

当我尝试(相同的图表配置)与ios-chart中给出的示例数据有效时!

let now = Date().timeIntervalSince1970
    let hourSeconds: TimeInterval = 60

    let from = now - (Double(100) / 2) * hourSeconds
    let to = now + (Double(100) / 2) * hourSeconds

    let values = stride(from: from, to: to, by: hourSeconds).map { (x) -> ChartDataEntry in
        let y = arc4random_uniform(range) + 50
        return ChartDataEntry(x: x, y: Double(y))
    }

如果我的图表配置是worng意味着(示例数据)也不起作用。

不知道问题出在哪里。

enter image description here

我的x轴值是正确的(我认为),因为我得到了x轴值。

UPDATE

Tapped随机从图表enter image description here中调出一个具有不同值集的相同代码按预期工作。

ios swift time ios-charts
1个回答
0
投票

一天后找到了答案。这是因为日期应该按顺序/升序(今天到明天)给出,我就像明天到今天一样。

© www.soinside.com 2019 - 2024. All rights reserved.