HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples/bullet-chart/horizontal-bullet-chart-with-ranges/data.json
4
anychart.data.loadJsonFile('https://cdn.anychart.com/samples/bullet-chart/horizontal-bullet-chart-with-ranges/data.json', function (data) {
5
var dataSet = data;
6
7
var table = anychart.standalones.table();
8
table.getCol(1)
9
.width(100)
10
.fontSize(7)
11
.vAlign('top')
12
13
table.contents([
14
[null, 'Region', null],
15
[null, 'Alabama', createBulletChart('Alabama')],
16
[null, 'Alaska', createBulletChart('Alaska'), null],
17
[null, 'Arizona', createBulletChart('Arizona'), null],
18
[null, 'Idaho', createBulletChart('Idaho'), null],
19
[null, 'Illinois', createBulletChart('Illinois'), null],
20
[null, 'Indiana', createBulletChart('Indiana'), null],
21
[null, 'Ohio', createBulletChart('Ohio'), null],
22
[null, 'Oklahoma', createBulletChart('Oklahoma'), null],
23
[null, 'Oregon', createBulletChart('Oregon'), null],
24
[null, 'Vermont', createBulletChart('Vermont'), null],
25
[null, 'Virginia', createBulletChart('Virginia'), null],
26
[null, 'Washington', createBulletChart('Washington'), null],
27
[null, 'Alabama', createBulletChart('Alabama'), null],
28
[null, 'Alaska', createBulletChart('Alaska'), null],
29
[null, 'Arizona', createBulletChart('Arizona'), null],
30
[null, 'Idaho', createBulletChart('Idaho'), null],
31
[null, 'Illinois', createBulletChart('Illinois'), null],
32
[null, 'Indiana', createBulletChart('Indiana'), null],
33
[null, 'Ohio', createBulletChart('Ohio'), null],
34
[null, 'Oklahoma', createBulletChart('Oklahoma'), null],
35
[null, 'Oregon', createBulletChart('Oregon'), null],
36
[null, 'Vermont', createBulletChart('Vermont'), null],
37
[null, 'Virginia', createBulletChart('Virginia'), null],
38
[null, 'Washington', createBulletChart('Washington'), null],
39
[null, 'Alabama', createBulletChart('Alabama'), null],
40
[null, 'Alaska', createBulletChart('Alaska'), null],
41
[null, 'Arizona', createBulletChart('Arizona'), null],
42
[null, 'Idaho', createBulletChart('Idaho'), null],
43
[null, 'Illinois', createBulletChart('Illinois'), null],
44
[null, 'Indiana', createBulletChart('Indiana'), null],
45
[null, 'Ohio', createBulletChart('Ohio'), null],
46
[null, 'Oklahoma', createBulletChart('Oklahoma'), null],
47
[null, 'Oregon', createBulletChart('Oregon'), null],
48
[null, 'Vermont', createBulletChart('Vermont'), null],
49
[null, 'Virginia', createBulletChart('Virginia'), null],
50
[null, 'Washington', createBulletChart('Washington'), null],
51
[null, 'Indiana', createBulletChart('Indiana'), null],
52
[null, 'Ohio', createBulletChart('Ohio'), null],
53
[null, 'Oklahoma', createBulletChart('Oklahoma'), null],
54
[null, 'Oregon', createBulletChart('Oregon'), null],
55
[null, 'Vermont', createBulletChart('Vermont'), null],
56
[null, 'Virginia', createBulletChart('Virginia'), null],
57
[null, 'Washington', createBulletChart('Washington'), null],
58
[null, null, null, null]
59
]);
60
table.getCol(0).width(40);
61
table.getCol(3).width(40);
62
63
table.container('container');
64
table.vAlign('middle');
65
table.draw();
66
67
function createBulletChart(name) {
68
var data = dataSet[name];
69
var target = eval(data['toGoal'].join('+'));
70
var actual = eval(data['actualSales'].join('+'));
71
var bullet = anychart.bullet([
72
{
73
value: Math.round(actual * 100 / target),
74
type: 'bar',
75
gap: 0.7,
76
fill: '#545f69',
77
stroke: null
78
},
79
{
80
value: 100,
81
type: 'line',
82
gap: 0,
83
fill: '#212121',
84
stroke: {
85
thickness: 2,
86
color: '#212121'
87
}
88
}
89
]);
90
91
bullet.range().from(0).to(30);
92
bullet.range(1).from(30).to(50);
93
bullet.range(2).from(50).to(80);
94
bullet.range(3).from(80).to(100);
95
bullet.range(4).from(100).to(130);
96
bullet.rangePalette(anychart.palettes.distinctColors().items(
97
[
98
'#dd2c00 0.4',
99
'#dd2c00 0.3',
100
'#ffa000 0.4',
101
'#006B00 0.3',
102
'#006B00 0.4'
103
]
104
));
105
bullet.scale()
106
.minimum(0)
107
.maximum(130);
108
109
bullet.margin(8, 0, 8, 0)
110
.axis(null)
111
.title(false)
112
.padding(0, -1)
113
.layout('horizontal');
114
115
return bullet;
116
}
117
});
118
});