Rails和Blazer 2折线图



如果有人熟悉Blazer/sql,我真的可以使用您的帮助:

我正在Blazer中创建一个折线图=>https://blazer.dokkuapp.com/queries/5-line-chart-format-2

图形样本

我想绘制[qikpac_id]和[reading_values.value]

但是需要过滤的阅读类型是什么;soc"@

WHERE reading_types.value = 'soc'

所以我最后有4列,我只想要

Y轴为reading_values.value

X作为读取时间

Qikpacs绘制值

到目前为止的sql查询:

SELECT
-- ## comented ## date_trunc('minute', reading_time)::date AS minute, 
reading_time,
reading_types.value as Reading_Type,
reading_values.value as Reading_Value,
qikpac_id as Qikpac 
FROM reading_values
INNER JOIN reading_types
ON reading_values.reading_type_id = reading_types.id
JOIN battery_statuses
ON reading_values.battery_status_id = battery_statuses.id
JOIN battery_readings
ON reading_values.battery_reading_id = battery_readings.id
WHERE reading_types.value = 'soc'
ORDER BY 1 

这让我:

| reading_time | reading_type | reading_value |  qikpac_id | 
2021-05-30 09:10:33 +1000   soc     49  13
2021-05-30 09:16:33 +1000   soc     49  14
2021-05-30 09:24:33 +1000   soc     49  15
2021-05-30 09:35:33 +1000   soc     49  16
2021-05-30 09:48:33 +1000   soc     49  13
2021-05-30 09:55:33 +1000   soc     49  14
2021-05-30 10:06:33 +1000   soc     49  15
2021-05-30 10:19:33 +1000   soc     49  16 

谢谢,我很困..:(

对于任何在下面搜索Blazer的人来说,答案是:

您需要通过以下方式订购:3列-时间戳、字符串、数字

而且开拓者在顺序和类型上都非常严格,否则你就不会像我那样快。

--      3 columns - timestamp, string, numeric
SELECT
date_trunc('minute', battery_readings.reading_time)::timestamp AS minute,
qikpacs.serial_number as Qikpac,
reading_values.value as Reading_Value
FROM reading_values
INNER JOIN reading_types
ON reading_values.reading_type_id = reading_types.id
JOIN battery_statuses
ON reading_values.battery_status_id = battery_statuses.id
JOIN battery_readings
ON reading_values.battery_reading_id = battery_readings.id
JOIN qikpacs
ON battery_readings.qikpac_id = qikpacs.id
WHERE reading_types.value = 'soc'
AND ( qikpacs.serial_number = 'QP016' )
GROUP BY battery_readings.reading_time,  qikpacs.serial_number, reading_values.value
ORDER BY battery_readings.reading_time,  qikpacs.serial_number, reading_values.value

图形图像

相关内容

  • 没有找到相关文章

最新更新