plot - Vega-Lite (Clojure Oz) 解析本地时间
问题描述
我通过Oz在 Clojure 中使用 Vega-Lite,因此下面的语法不是严格的 JSON,但希望您能看到语法如何映射到 JSON。
我正在尝试创建一个非常简单的时间序列图,其中 x 轴是以小时为单位的时间,例如“18:00”<--当地时间下午 6:00。到目前为止,如果我使用解析器,我只能让 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 正确解析时间和/或如何表示时间,{:data :{values...}}
以便 Vega-Lite 可以理解当地时间并用它绘图吗?
解决方案
只需提供以下: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"
}
推荐阅读
- php - How do I populate this placeholder info for a GoDaddy email form?
- c# - In C # how to change a value in a JObject, having the token in string format?
- java - Has conversion between Instant and Date changed from Java 8 to 11?
- javascript - On some pages don't show Menu Component but it is visible for a while
- batch-file - I am trying to add a line to the end of a concatinated txt file
- javascript - Sharepoint:如何根据搜索关键字过滤常见问题列表
- android - 创建的视图不在给定的坐标处
- c# - 在 OnSleep 应用程序之后单击主页上的按钮显示 SplashScreen
- angular - 带有自签名 SSL 证书的浏览器推送通知
- ruby-on-rails - 使用 Rails 乐观锁定实时编辑器数据