Vega-Lite (Clojure Oz) 解析本地时间
Vega-Lite (Clojure Oz) Parsing Local Time
我通过 Oz 在 Clojure 中使用 Vega-Lite,所以下面的语法不是严格的 JSON,但希望你能看到语法如何映射到 JSON .
我正在尝试创建一个非常简单的时间序列图,其中 x 轴是以小时分钟为单位的时间,例如“18:00” <-- 6:00pm 当地时间。到目前为止,如果我使用解析器,我只能让 Vega Lite 识别时间。以下代码有效,但它输出为 UTC 时间而不是本地时间。我不知道如何让 Vega-Lite 将其解析为当地时间。
有人可以帮忙吗?
(def test-plot
{:data {:values
[{:time "18:00" :volume 10}
{:time "18:02" :volume 41}
{:time "18:07" :volume 192}
{:time "18:30" :volume 257}
{:time "19:00" :volume 300}]
:format {:parse {:time "utc:'%H:%M'"}}}
:encoding {:x {:field "time" :type "temporal" :timeUnit "hoursminutes"}
:y {:field "volume" :type "quantitative"}}
:mark "point"})
;;; to compile and view in Clojure - Oz:
(do
(println "calling (oz/start-server!)")
(oz/start-server!)
(println "calling (oz/view!)")
(oz/view! test-plot)
(println "calling (Thread/sleep)")
(Thread/sleep 5000))
如果我使用 :format {:parse {:time "utc:'%H:%M'"}}}
然后我得到下面的图像,其中 Vega-Lite 正确解析时间然后转换为 UTC 时间。
如果我尝试删除 utc
,例如:format {:parse {:time "'%H:%M'"}}}
,然后我得到这张图像,其中 Vega-Lite 不再正确解析时间。
有人能帮我弄清楚如何让 Vega-Lite 正确解析时间 and/or 如何在 {:data :{values...}}
中表示时间,以便 Vega-Lite 可以理解本地时间并用是吗?
只需提供以下内容:format {:parse {:time "date:'%H:%M'"}}}
,您就会得到以您当地时间绘制的图表。您可以参考下面的配置或editor:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"time": "18:00", "volume": 10},
{"time": "18:02", "volume": 41},
{"time": "18:07", "volume": 192},
{"time": "18:30", "volume": 257},
{"time": "19:00", "volume": 300}
],
"format": {"parse": {"time": "date:'%H:%M'"}}
},
"encoding": {
"x": {"field": "time", "type": "temporal", "timeUnit": "hoursminutes"},
"y": {"field": "volume", "type": "quantitative"}
},
"mark": "point"
}
我通过 Oz 在 Clojure 中使用 Vega-Lite,所以下面的语法不是严格的 JSON,但希望你能看到语法如何映射到 JSON .
我正在尝试创建一个非常简单的时间序列图,其中 x 轴是以小时分钟为单位的时间,例如“18:00” <-- 6:00pm 当地时间。到目前为止,如果我使用解析器,我只能让 Vega Lite 识别时间。以下代码有效,但它输出为 UTC 时间而不是本地时间。我不知道如何让 Vega-Lite 将其解析为当地时间。
有人可以帮忙吗?
(def test-plot
{:data {:values
[{:time "18:00" :volume 10}
{:time "18:02" :volume 41}
{:time "18:07" :volume 192}
{:time "18:30" :volume 257}
{:time "19:00" :volume 300}]
:format {:parse {:time "utc:'%H:%M'"}}}
:encoding {:x {:field "time" :type "temporal" :timeUnit "hoursminutes"}
:y {:field "volume" :type "quantitative"}}
:mark "point"})
;;; to compile and view in Clojure - Oz:
(do
(println "calling (oz/start-server!)")
(oz/start-server!)
(println "calling (oz/view!)")
(oz/view! test-plot)
(println "calling (Thread/sleep)")
(Thread/sleep 5000))
如果我使用 :format {:parse {:time "utc:'%H:%M'"}}}
然后我得到下面的图像,其中 Vega-Lite 正确解析时间然后转换为 UTC 时间。
如果我尝试删除 utc
,例如:format {:parse {:time "'%H:%M'"}}}
,然后我得到这张图像,其中 Vega-Lite 不再正确解析时间。
有人能帮我弄清楚如何让 Vega-Lite 正确解析时间 and/or 如何在 {:data :{values...}}
中表示时间,以便 Vega-Lite 可以理解本地时间并用是吗?
只需提供以下内容:format {:parse {:time "date:'%H:%M'"}}}
,您就会得到以您当地时间绘制的图表。您可以参考下面的配置或editor:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"time": "18:00", "volume": 10},
{"time": "18:02", "volume": 41},
{"time": "18:07", "volume": 192},
{"time": "18:30", "volume": 257},
{"time": "19:00", "volume": 300}
],
"format": {"parse": {"time": "date:'%H:%M'"}}
},
"encoding": {
"x": {"field": "time", "type": "temporal", "timeUnit": "hoursminutes"},
"y": {"field": "volume", "type": "quantitative"}
},
"mark": "point"
}