简体   繁体   English

参数化 Vega 或 Vega-lite 数据 url?

[英]Parametrize Vega or Vega-lite data url?

I am trying to create a Vega/Vega-lite data fetch based on a parameter/transform/signal defined later down in the chart specification.我正在尝试基于稍后在图表规范中定义的参数/转换/信号创建 Vega/Vega-lite 数据提取。 Is this possible?这可能吗? It would be of tremendous use with fetching data from parametric APIs.从参数 API 获取数据将非常有用。 Eg instead of:例如,而不是:

"data" : {"url" : "https://api.carbonintensity.org.uk/intensity/2021-12-04/fw48h"}

I would like:我想:

"data" : {"url": "'https://api.carbonintensity.org.uk/intensity/'+myDate+'/fw48h'"}
"transform": [ {"calculate": "'2021-12-04'", "as":"myDate"} ]

The URL can be specified as Vega signal expression. URL 可以指定为 Vega 信号表达式。 Assuming myDate is a named signal with valid string value, try:假设myDate是具有有效字符串值的命名信号,请尝试:

"data" : {"url": {"signal": "'https://api.carbonintensity.org.uk/intensity/' + myDate + '/fw48h'"},
          "transform": ...
          }

Here is an example of Vega tutorial https://vega.github.io/vega/tutorials/airports/这里是一个 Vega 教程示例https://vega.github.io/vega/tutorials/airports/

with the part of url path for traffic data from a signal value. url 路径的一部分用于交通数据的信号值。

View in Vega on-line editor 在 Vega 在线编辑器中查看

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

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