简体   繁体   English

Vega-Lite (Clojure Oz) 解析本地时间

[英]Vega-Lite (Clojure Oz) Parsing Local Time

I'm using Vega-Lite in Clojure through Oz so the syntax below isn't a strict JSON, but hopefully you can see how the syntax maps to JSON.我在 Clojure 到Oz中使用 Vega-Lite,所以下面的语法不是严格的 JSON,但希望你能看到语法如何映射到 Z0ECD11C1D7A287401D148A23BBD7A2F8。

I'm trying to create a very simple time-series plot where the x-axis is time in hours minutes, eg "18:00" <-- 6:00pm local time.我正在尝试创建一个非常简单的时间序列 plot ,其中 x 轴是以小时为单位的时间,例如“18:00”<--当地时间下午 6:00。 So far I've only been able to get Vega Lite to recognize the time if I use a parser.到目前为止,如果我使用解析器,我只能让 Vega Lite 识别时间。 The following code works, but it outputs to UTC time rather than local time.以下代码有效,但它输出到 UTC 时间而不是本地时间。 I can't figure out how to get Vega-Lite to parse it to local time.我不知道如何让 Vega-Lite 将其解析为当地时间。

Can someone please help?有人可以帮忙吗?

(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))

If I use :format {:parse {:time "utc:'%H:%M'"}}} then I get the image below, where Vega-Lite parses the time correctly and then transforms to UTC time.如果我使用:format {:parse {:time "utc:'%H:%M'"}}}那么我得到下面的图像,其中 Vega-Lite 正确解析时间然后转换为 UTC 时间。 在此处输入图像描述

If however I attempt to remove utc , eg :format {:parse {:time "'%H:%M'"}}} , then I get this image where Vega-Lite no longer parses the time correctly.但是,如果我尝试删除utc ,例如:format {:parse {:time "'%H:%M'"}}} ,那么我会得到这个 Vega-Lite 不再正确解析时间的图像。 在此处输入图像描述

Can someone please help me figure out how to get Vega-Lite to parse the time correctly and/or how to represent time in {:data:{values...}} such that Vega-Lite can understand local time and plot with it?有人可以帮我弄清楚如何让 Vega-Lite 正确解析时间和/或如何在{:data:{values...}}中表示时间,以便 Vega-Lite 可以理解当地时间和 plot ?

Just provide the following :format {:parse {:time "date:'%H:%M'"}}} and you will get the chart plotted in your local time.只需提供以下:format {:parse {:time "date:'%H:%M'"}}} ,您将获得在本地时间绘制的图表。 You can refer the below config or 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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM