如何在折线图中只显示 24 小时柱?
How to show only 24hr column in line chart?
我正在使用图表-ios library,我设法在图表中显示数据,如下图所示。
我的 Json 数据如下。我在 X 轴上显示 field1+field2+field3
,在 y 轴上显示 created_at
。此数据为 1 天。
[
{
"created_at": "2020-05-10T00:01:09Z",
"field1": 17.57,
"field2": 56.37,
"field3": 44.06,
"equipment": 3
},
{
"created_at": "2020-05-10T00:01:55Z",
"field1": 17.57,
"field2": 54.52,
"field3": 44.62,
"equipment": 3
},
{
"created_at": "2020-05-10T00:02:40Z",
"field1": 21.63,
"field2": 52.7,
"field3": 51.27,
"equipment": 3
},
{
"created_at": "2020-05-10T00:03:26Z",
"field1": 17.15,
"field2": 54.95,
"field3": 44.21,
"equipment": 3
},
{
"created_at": "2020-05-10T00:04:12Z",
"field1": 15.97,
"field2": 54.69,
"field3": 41.36,
"equipment": 3
},
{
"created_at": "2020-05-10T00:04:57Z",
"field1": 15.86,
"field2": 38.58,
"field3": 36.59,
"equipment": 3
},
{
"created_at": "2020-05-10T00:05:43Z",
"field1": 7.66,
"field2": 51.6,
"field3": 45.46,
"equipment": 3
}
..... 1000 more...
]
我想要的是以 1 小时为间隔显示 x 轴标签。像 11:00、12:00 和 13:00 等等。我想展示的是固定的 24 小时,仅此而已。但 x 值计数超过 1000 条记录。
那我该怎么做呢?谁能指出我正确的方向?
谢谢
- X 值需要是 Double -> 通常我使用 timeIntervalSince1970
- 您需要一个 CustomValueFormatter
- 将 xAxis 最小值设置为 00:00
- 将 xAxis 最大值设置为 00:00 + 1 天
- xAxis.granularity = 3600 -> 每小时只显示标签
- chart.setVisibleXRange(minXRange: 5 * 3600, maxXRange: 5 * 3600) -> 滚动时仅显示 5 小时范围
检查这个项目:https://github.com/aiwiguna/ExampleCharts/tree/feature/hourly-charts
我正在使用图表-ios library,我设法在图表中显示数据,如下图所示。
我的 Json 数据如下。我在 X 轴上显示 field1+field2+field3
,在 y 轴上显示 created_at
。此数据为 1 天。
[
{
"created_at": "2020-05-10T00:01:09Z",
"field1": 17.57,
"field2": 56.37,
"field3": 44.06,
"equipment": 3
},
{
"created_at": "2020-05-10T00:01:55Z",
"field1": 17.57,
"field2": 54.52,
"field3": 44.62,
"equipment": 3
},
{
"created_at": "2020-05-10T00:02:40Z",
"field1": 21.63,
"field2": 52.7,
"field3": 51.27,
"equipment": 3
},
{
"created_at": "2020-05-10T00:03:26Z",
"field1": 17.15,
"field2": 54.95,
"field3": 44.21,
"equipment": 3
},
{
"created_at": "2020-05-10T00:04:12Z",
"field1": 15.97,
"field2": 54.69,
"field3": 41.36,
"equipment": 3
},
{
"created_at": "2020-05-10T00:04:57Z",
"field1": 15.86,
"field2": 38.58,
"field3": 36.59,
"equipment": 3
},
{
"created_at": "2020-05-10T00:05:43Z",
"field1": 7.66,
"field2": 51.6,
"field3": 45.46,
"equipment": 3
}
..... 1000 more...
]
我想要的是以 1 小时为间隔显示 x 轴标签。像 11:00、12:00 和 13:00 等等。我想展示的是固定的 24 小时,仅此而已。但 x 值计数超过 1000 条记录。
那我该怎么做呢?谁能指出我正确的方向?
谢谢
- X 值需要是 Double -> 通常我使用 timeIntervalSince1970
- 您需要一个 CustomValueFormatter
- 将 xAxis 最小值设置为 00:00
- 将 xAxis 最大值设置为 00:00 + 1 天
- xAxis.granularity = 3600 -> 每小时只显示标签
- chart.setVisibleXRange(minXRange: 5 * 3600, maxXRange: 5 * 3600) -> 滚动时仅显示 5 小时范围
检查这个项目:https://github.com/aiwiguna/ExampleCharts/tree/feature/hourly-charts