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