legend - Vega 图例和每标记颜色
问题描述
正如您在示例中看到的,我想创建一个带有多个标记的图表。这些标记中的每一个都需要特定的颜色、相应的标签和图例。我知道我通过“域”定义颜色:{“数据”:“表”,“字段”:“区域”}。但是我的“小计”和“总计”行需要特定的颜色。图例应为 Neustadt - Totals 和 Neustadt - Subtotals。
我已经玩过可以在scales文档中找到的内容。但我似乎无法通过引用标记字段制作颜色和图例项目。
"data": [
{
"name": "table",
"values": [
{"District": "Neustadt", "total": "86", "id": 12, "subtotal": "600", "Year": "2017"},
{"District": "Neustadt", "total": "398", "id": 13, "subtotal": "100", "Year": "2018"},
{"District": "Neustadt", "total": "155", "id": 14, "subtotal": "10", "Year": "2019"}
],
"transform": [
{
"type": "collect",
"sort": {
"field": "Year"
}
}
]
}
],
"scales": [
{
"name": "Year",
"type": "point",
"range": "width",
"domain": {"data": "table", "field": "Year", "sort": true}
},
{
"name": "subtotal",
"type": "linear",
"range": "height",
"nice": true,
"zero": true,
"domain": {"data": "table", "field": "subtotal"}
},
{
"name": "color",
"type": "ordinal",
"range": "category",
"domain": {"data": "table", "field": "District"}
}
]
如果我在数据中有另一个区域,我只能得到一个图例项目,当然也只能得到多个项目。分组标记是一种选择吗?
解决方案
推荐阅读
- perl - 从 perl 数组中删除重复的哈希
- python - 掷骰子游戏的一些建议
- python - 在 GNU Radio 中使用 USRP 进行频谱感知
- flutter - Flutter WEB 下载选项
- ios - 在 iOS 中:我的应用程序能否启动另一个应用程序并获得回复/确认?
- jenkins - 了解构建日志文件详细信息
- spring-boot - 反应式 REST API 分页
- testing - 如何测量基于 Flash 的游戏的性能数据?
- python - 如何从具有不同长度的列表列表中创建 Pandas DataFrame?
- git - Squash 在 Github 上将一个分支合并到 master 中,但缺少一些更改