简体   繁体   中英

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. Is this possible? It would be of tremendous use with fetching data from parametric APIs. 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. Assuming myDate is a named signal with valid string value, try:

"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/

with the part of url path for traffic data from a signal value.

View in Vega on-line editor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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