1
|
{
|
2
|
"$schema": "https://vega.github.io/schema/vega/v5.json",
|
3
|
"description": "A basic bar chart example, with value labels shown upon mouse hover.",
|
4
|
"width": 400,
|
5
|
"height": 200,
|
6
|
"padding": 5,
|
7
|
|
8
|
"data": [
|
9
|
{
|
10
|
"name": "table",
|
11
|
"values": [
|
12
|
{"category": "A", "amount": 28},
|
13
|
{"category": "B", "amount": 55},
|
14
|
{"category": "C", "amount": 43},
|
15
|
{"category": "D", "amount": 91},
|
16
|
{"category": "E", "amount": 81},
|
17
|
{"category": "F", "amount": 53},
|
18
|
{"category": "G", "amount": 19},
|
19
|
{"category": "H", "amount": 87}
|
20
|
]
|
21
|
}
|
22
|
],
|
23
|
|
24
|
"signals": [
|
25
|
{
|
26
|
"name": "tooltip",
|
27
|
"value": {},
|
28
|
"on": [
|
29
|
{"events": "rect:mouseover", "update": "datum"},
|
30
|
{"events": "rect:mouseout", "update": "{}"}
|
31
|
]
|
32
|
}
|
33
|
],
|
34
|
|
35
|
"scales": [
|
36
|
{
|
37
|
"name": "xscale",
|
38
|
"type": "band",
|
39
|
"domain": {"data": "table", "field": "category"},
|
40
|
"range": "width",
|
41
|
"padding": 0.05,
|
42
|
"round": true
|
43
|
},
|
44
|
{
|
45
|
"name": "yscale",
|
46
|
"domain": {"data": "table", "field": "amount"},
|
47
|
"nice": true,
|
48
|
"range": "height"
|
49
|
}
|
50
|
],
|
51
|
|
52
|
"axes": [
|
53
|
{ "orient": "bottom", "scale": "xscale" },
|
54
|
{ "orient": "left", "scale": "yscale" }
|
55
|
],
|
56
|
|
57
|
"marks": [
|
58
|
{
|
59
|
"type": "rect",
|
60
|
"from": {"data":"table"},
|
61
|
"encode": {
|
62
|
"enter": {
|
63
|
"x": {"scale": "xscale", "field": "category"},
|
64
|
"width": {"scale": "xscale", "band": 1},
|
65
|
"y": {"scale": "yscale", "field": "amount"},
|
66
|
"y2": {"scale": "yscale", "value": 0}
|
67
|
},
|
68
|
"update": {
|
69
|
"fill": {"value": "steelblue"}
|
70
|
},
|
71
|
"hover": {
|
72
|
"fill": {"value": "red"}
|
73
|
}
|
74
|
}
|
75
|
},
|
76
|
{
|
77
|
"type": "text",
|
78
|
"encode": {
|
79
|
"enter": {
|
80
|
"align": {"value": "center"},
|
81
|
"baseline": {"value": "bottom"},
|
82
|
"fill": {"value": "#333"}
|
83
|
},
|
84
|
"update": {
|
85
|
"x": {"scale": "xscale", "signal": "tooltip.category", "band": 0.5},
|
86
|
"y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -2},
|
87
|
"text": {"signal": "tooltip.amount"},
|
88
|
"fillOpacity": [
|
89
|
{"test": "datum === tooltip", "value": 0},
|
90
|
{"value": 1}
|
91
|
]
|
92
|
}
|
93
|
}
|
94
|
}
|
95
|
]
|
96
|
}
|