HTMLcopy
1
<div id="compteur"></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
// créer un ensemble de données
3
var dataSet = anychart.data.set([
4
28]],
5
]);
6
7
var analyseData = roundDecimal(28.777, 1);
8
9
//Créer le compteur anyChart
10
var gauge = anychart.gauges.circular();
11
12
//Reliée les données avec le compteur
13
gauge
14
.data(dataSet);
15
16
//Création de la forme du compteur
17
gauge
18
.fill('white')
19
.stroke(null)
20
.padding(0)
21
.margin(0, 30)
22
.startAngle(270)
23
.sweepAngle(180)
24
.axis()
25
.labels()
26
.fontSize(8)
27
.position('outside')
28
.format('{%Value} %');
29
30
//pour crée un label
31
gauge
32
.label(1)
33
.text('<span style="color: red"> C16:0 = <strong>' + analyseData.toString().replace('.',',') + '</strong> % </span>')
34
.useHtml(true)
35
.hAlign('center')
36
.anchor('center-top')
37
.padding(5, 10)
38
.fontSize(12)
39
.offsetY(-15)
40
.offsetX(90)
41
.zIndex(1)
42
.background({
43
fill: 'white',
44
stroke: '#c1c1c1',
45
corners: 5,
46
cornerType: 'ROUND'
47
});
48
49
// pour gerer les intervales de valeur
50
gauge
51
.axis()
52
.scale()
53
.minimum(25)
54
.maximum(35)
55
.ticks({
56
interval: 5
57
})
58
.minorTicks({
59
interval: 1
60
});
61
62
// pour gerer l'interface des intervales
63
gauge
64
.axis()
65
.fill('grey')
66
.width(1)
67
.ticks({ type: 'line', fill: 'white', length: 2 });
68
69
// Gestion des aiguilles
70
gauge
71
.needle()
72
.stroke('4 #545f69')
73
.startRadius('70%')
74
.endRadius('97%')
75
.startWidth('0.1%')
76
.endWidth('0.1%')
77
.middleWidth('0.1%');
78
79
//Rond au milieu
80
gauge.cap()
81
82
.radius('45%')
83
.enabled(true)
84
.fill('#ffa000')
85
.stroke('4 white');
86
87
88
gauge.range(0, {
89
from: 25,
90
to: 27.5,
91
position: 'inside',
92
fill: '#64A70B',
93
startSize: 30,
94
endSize: 30,
95
radius: 98
96
});
97
98
gauge.range(1, {
99
from: 27.5,
100
to: 30,
101
position: 'inside',
102
fill: '#9CC764',
103
startSize: 30,
104
endSize: 30,
105
radius: 98
106
});
107
108
gauge.range(2, {
109
from: 30,
110
to: 32.5,
111
position: 'inside',
112
fill: '#C7DFA6',
113
startSize: 30,
114
endSize: 30,
115
radius: 98
116
});
117
118
gauge.range(3, {
119
from: 32.5,
120
to: 35,
121
position: 'inside',
122
fill: '#E3EFD3',
123
startSize: 30,
124
endSize: 30,
125
radius: 98
126
});
127
128
129
//gestion des tooltips
130
gauge.tooltip().format(function (e) {
131
var value = (this.value);
132
return value + "%";
133
});
134
135
gauge.container('compteur');
136
gauge.draw();
137
});