在 Vega 中从外部 API 加载数据
Loading data from external API in Vega
当我尝试改变 https://vega.github.io/editor/#/examples/vega/scatter-plot 时,
- "url": "data/cars.json"
+ "url": "http://dummy.restapiexample.com/api/v1/employees",
我收到一个错误,
loader.js:166 Mixed Content: The page at 'https://vega.github.io/editor/#/edited' was loaded over HTTPS, but requested an insecure resource 'http://dummy.restapiexample.com/api/v1/employees'. This request has been blocked; the content must be served over HTTPS.
如何从外部 API 获取数据?
很简单。我只需要使用相同的协议 HTTPS --> HTTPS
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"description": "A scatterplot showing horsepower and miles per gallons for various cars.",
"data": {"url": "https://jsonplaceholder.typicode.com/todos"},
"mark": "point",
"encoding": {
"x": {"field": "userId","type": "quantitative"},
"y": {"field": "id","type": "quantitative"}
}
}
当我尝试改变 https://vega.github.io/editor/#/examples/vega/scatter-plot 时,
- "url": "data/cars.json"
+ "url": "http://dummy.restapiexample.com/api/v1/employees",
我收到一个错误,
loader.js:166 Mixed Content: The page at 'https://vega.github.io/editor/#/edited' was loaded over HTTPS, but requested an insecure resource 'http://dummy.restapiexample.com/api/v1/employees'. This request has been blocked; the content must be served over HTTPS.
如何从外部 API 获取数据?
很简单。我只需要使用相同的协议 HTTPS --> HTTPS
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"description": "A scatterplot showing horsepower and miles per gallons for various cars.",
"data": {"url": "https://jsonplaceholder.typicode.com/todos"},
"mark": "point",
"encoding": {
"x": {"field": "userId","type": "quantitative"},
"y": {"field": "id","type": "quantitative"}
}
}