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

标签 ios swift time ios-charts

我正在 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))
    }

如果我的图表配置很糟糕,则意味着(示例数据)也无法正常工作。

不知道哪里出了问题。

enter image description here

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

更新

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

最佳答案

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

关于ios-chart 值不会基于 x 和 y 轴 Swift 绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47927448/

相关文章:

android - Websocket 服务器作为 Azure 上的服务?

ios - 反复更改 View 的背景颜色并使用动画

ios - 使用 CoreData 以编程方式创建实体/表,并在适用于 iOS 的 Swift 3 中将值插入该实体

swift - 从 Parse 下载后无法流式传输视频

c - C 中数组的大小是否会影响访问或更改数组中的一段数据的时间

java - 将数据库时间转换为 IST 日期时间

ios - 如何将 ImageView 转换并放大为形状(swift3)

android - Xamarin Forms - IOS - 汉堡包菜单标题颜色与状态栏不同

ios - 如何更改 UITabbarController 的更多 ViewControllers UITableViewCells 图像?

python - 自然语言时间解析器