[英]Vega lite add an Interactive Point Highlight
Could anyone helps me to add interactive highlight point on hover?谁能帮我在 hover 上添加交互式亮点? I tried to add props from this example , but it did not work for me.我试图从这个例子中添加道具,但它对我不起作用。
Here is my spec at Vega Lite Editor这是我在Vega Lite Editor的规格
The example is Vega-Lite but your spec is Vega.示例是 Vega-Lite,但您的规格是 Vega。 Try this - it gives a point and a tooltip for you.试试这个 - 它为您提供了一个要点和一个工具提示。
{
"description": "Total Count line chart.",
"width": 1200,
"height": 450,
"padding": 5,
"signals": [{"name": "interpolate", "value": "linear"}],
"legends": [
{
"fill": "color",
"orient": "bottom",
"direction": "horizontal",
"symbolType": "square"
}
],
"data": [
{
"name": "table",
"values": [
{"x": 0, "y": 145, "c": "All"},
{"x": 1, "y": 153, "c": "All"},
{"x": 2, "y": 280, "c": "All"},
{"x": 3, "y": 150, "c": "All"},
{"x": 4, "y": 280, "c": "All"},
{"x": 5, "y": 140, "c": "All"},
{"x": 6, "y": 90, "c": "All"},
{"x": 0, "y": 30, "c": "Bulk carrier"},
{"x": 1, "y": 20, "c": "Bulk carrier"},
{"x": 2, "y": 90, "c": "Bulk carrier"},
{"x": 3, "y": 60, "c": "Bulk carrier"},
{"x": 4, "y": 50, "c": "Bulk carrier"},
{"x": 5, "y": 40, "c": "Bulk carrier"},
{"x": 6, "y": 10, "c": "Bulk carrier"},
{"x": 0, "y": 50, "c": "Tanker ship"},
{"x": 1, "y": 10, "c": "Tanker ship"},
{"x": 2, "y": 50, "c": "Tanker ship"},
{"x": 3, "y": 40, "c": "Tanker ship"},
{"x": 4, "y": 110, "c": "Tanker ship"},
{"x": 5, "y": 40, "c": "Tanker ship"},
{"x": 6, "y": 20, "c": "Tanker ship"},
{"x": 0, "y": 5, "c": "Dingy"},
{"x": 1, "y": 23, "c": "Dingy"},
{"x": 2, "y": 20, "c": "Dingy"},
{"x": 3, "y": 0, "c": "Dingy"},
{"x": 4, "y": 30, "c": "Dingy"},
{"x": 5, "y": 20, "c": "Dingy"},
{"x": 6, "y": 0, "c": "Dingy"},
{"x": 0, "y": 50, "c": "Carrier ship"},
{"x": 1, "y": 60, "c": "Carrier ship"},
{"x": 2, "y": 90, "c": "Carrier ship"},
{"x": 3, "y": 40, "c": "Carrier ship"},
{"x": 4, "y": 50, "c": "Carrier ship"},
{"x": 5, "y": 20, "c": "Carrier ship"},
{"x": 6, "y": 40, "c": "Carrier ship"},
{"x": 0, "y": 10, "c": "Other"},
{"x": 1, "y": 40, "c": "Other"},
{"x": 2, "y": 30, "c": "Other"},
{"x": 3, "y": 10, "c": "Other"},
{"x": 4, "y": 40, "c": "Other"},
{"x": 5, "y": 20, "c": "Other"},
{"x": 6, "y": 20, "c": "Other"}
]
}
],
"scales": [
{
"name": "x",
"type": "point",
"range": "width",
"domain": {"data": "table", "field": "x"}
},
{
"name": "y",
"type": "linear",
"range": "height",
"nice": true,
"zero": true,
"domain": {"data": "table", "field": "y"}
},
{
"name": "color",
"type": "ordinal",
"range": [
"#61c7f7",
"#BA20CE",
"#60cf85",
"#cd2c4f",
"#ceae39",
"#ffffff"
],
"domain": {"data": "table", "field": "c"}
}
],
"axes": [
{"orient": "bottom", "scale": "x"},
{"orient": "left", "scale": "y"}
],
"config": {
"style": {
"guide-label": {"fontSize": 14, "fill": "#cccccc", "fontWeight": 800}
},
"axis": {"grid": true, "gridColor": "#333333"}
},
"marks": [
{
"type": "group",
"from": {"facet": {"name": "series", "data": "table", "groupby": "c"}},
"marks": [
{
"type": "line",
"from": {"data": "series"},
"encode": {
"enter": {
"x": {"scale": "x", "field": "x"},
"y": {"scale": "y", "field": "y"},
"stroke": {"scale": "color", "field": "c"},
"strokeWidth": {"value": 2}
},
"update": {
"interpolate": {"signal": "interpolate"},
"strokeOpacity": {"value": 1}
},
"hover": {"strokeOpacity": {"value": 0.5}}
}
},
{
"type": "symbol",
"from": {"data": "series"},
"encode": {
"update": {
"x": {"scale": "x", "field": "x"},
"y": {"scale": "y", "field": "y"},
"fillOpacity": {"value": 0}
},
"hover": {"fillOpacity": {"value": 1},
"tooltip": {
"signal": "{'c':datum.c }"
}
}
}
}
]
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.