我通过奥兹在Clojure中使用Vega,所以下面的语法不是一个严格的JSON,但希望您能够看到语法如何映射到JSON。
我试图创建一个非常简单的时间序列图,其中x轴是以小时分钟为单位的时间,例如"18:00“<--当地时间下午6:00。到目前为止,我只能让Vega在使用解析器时识别时间。下面的代码可以工作,但它输出到UTC时间而不是本地时间。我不知道怎么让Vega把它解析到当地时间。
有人能帮忙吗?
(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正确地解析时间,然后转换为UTC时间。

然而,如果我试图删除utc,例如:format {:parse {:time "'%H:%M'"}}},那么我就会得到这个图像,其中Vega不再正确地解析时间。

有人能帮我弄清楚如何让Vega正确地解析时间和/或如何在{:data :{values...}}中表示时间,以便Vega能够理解本地时间并用它进行绘图?
发布于 2021-04-16 05:17:58
只需提供以下:format {:parse {:time "date:'%H:%M'"}}},您就可以在当地时间绘制图表。您可以参考下面的配置或编辑器
{
"$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"
}https://stackoverflow.com/questions/67115226
复制相似问题