Vega-Lite:多折线图的特定标记颜色

时间:2018-08-22 16:47:16

标签: vega-lite

如何设置存储在数据字段中的线条颜色? 在Vega中,我做了:

marks :[
 {
   encode: {
     enter: {
       ...
       stroke: {field: "color"}
      }
    }
  }
]

Vega-Lite中有类似的方法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用带有color标记的line编码。 vega-lite网站上有一些示例;相关的一个是Multi Series Line Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "description": "Stock prices of 5 Tech Companies over Time.",
  "data": {"url": "data/stocks.csv"},
  "mark": "line",
  "encoding": {
    "x": {"field": "date", "type": "temporal"},
    "y": {"field": "price", "type": "quantitative"},
    "color": {"field": "symbol", "type": "nominal"}
  }
}

enter image description here