首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vega (Clojure Oz)本地时间解析

Vega (Clojure Oz)本地时间解析
EN

Stack Overflow用户
提问于 2021-04-15 19:54:13
回答 1查看 166关注 0票数 1

我通过奥兹在Clojure中使用Vega,所以下面的语法不是一个严格的JSON,但希望您能够看到语法如何映射到JSON。

我试图创建一个非常简单的时间序列图,其中x轴是以小时分钟为单位的时间,例如"18:00“<--当地时间下午6:00。到目前为止,我只能让Vega在使用解析器时识别时间。下面的代码可以工作,但它输出到UTC时间而不是本地时间。我不知道怎么让Vega把它解析到当地时间。

有人能帮忙吗?

代码语言:javascript
复制
(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能够理解本地时间并用它进行绘图?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-16 05:17:58

只需提供以下:format {:parse {:time "date:'%H:%M'"}}},您就可以在当地时间绘制图表。您可以参考下面的配置或编辑器

代码语言:javascript
复制
{
  "$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"
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67115226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档