多用途-半圆形-指针仪表盘2
# FastWeb 360度浏览-公转视角-商品固定
圆形指针的仪表盘使用的是Canvas Gauges
,这是一套丰富的JS仪表盘组件库。
使用的半圆形指针仪表盘的样式如下:

# 1. 下载示例
点击https://github.com/Mikhus/canvas-gauges/archive/refs/heads/master.zip (opens new window)以下载库,建议将其中包含的内容解压缩放置于FastWeb目录的library/js
文件夹中。
# 2. 确认参数
半圆形指针仪表盘的样式内容如下:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gauge Test</title>
<link rel="stylesheet" href="library/js/canvas-gauges-master/fonts/fonts.css">
<script src="library/js/canvas-gauges-master/gauge.min.js"></script>
</head>
<body style="background: #fff">
<canvas id="canvasPressure"></canvas>
<script>
var gaugePressure = new RadialGauge({
renderTo: 'canvasPressure',
width: 300,
height: 300,
units: "1010 hPa",
startAngle: 70,
ticksAngle: 220,
colorPlate: "#ffffff",
colorUnits: "#3CA7DB",
colorNumbers: "#3CA7DB",
needleType: "arrow",
needleStart: 0,
needleEnd: 75,
needleWidth: 4,
needleCircleSize: 10,
needleCircleInner: false,
needleCircleOuter: true,
needleShadow: false,
colorNeedle: "#3CA7DB",
colorNeedleEnd: "#2698CE",
colorNeedleCircleOuter: "#3CA7DB",
colorNeedleCircleOuterEnd: "#3CA7DB",
colorMajorTicks: [
"#A8D3D5",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#A8D3D5"
],
colorMinorTicks: "#ffffff",
minValue: 975,
maxValue: 1045,
majorTicks: [
"",
"980",
"",
"990",
"",
"1000",
"",
"1010",
"",
"1020",
"",
"1030",
"",
"1040",
""
],
minorTicks: "10",
strokeTicks: true,
highlights: [
{
"from": 974.75,
"to": 1045.25,
"color": "#A8D3D5"
}
],
highlightsWidth: 25,
numbersMargin: 12,
animation: true,
animationRule: "linear",
valueBox: false,
borders: false,
borderShadowWidth: 0,
value: 1024,
animateOnInit: true,
animatedValue: true
}).draw();
var timers = [];
function animateGauges() {
document.gauges.forEach(function (gauge) {
timers.push(setInterval(function () {
gauge.value = Math.random() *
(gauge.options.maxValue - gauge.options.minValue) +
gauge.options.minValue;
}, gauge.animation.duration + 50));
});
}
window.addEventListener('load', function () {
document.gauges.forEach(function (gauge) {
gauge.on('animate', function (percent, value) {
gauge.update({ units: parseInt(value, 10) + ' hPa' });
});
});
});
</script>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
从上述的语言中,可以找到一个名为value
的参数,其中得到的值就是半圆形仪表盘指针指向的数值。此处可为其设置参数值为param_value
。
# 3. 修改模板
# 3.1. 本地化处理
上述模板已经将所需的文件本地化处理,不需要额外进行本地化的相关设置。
# 3.2. 标记参数
将上述的value
处后的值使用param_value
来代替,替换后的内容如下:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gauge Test</title>
<link rel="stylesheet" href="library/js/canvas-gauges-master/fonts/fonts.css">
<script src="library/js/canvas-gauges-master/gauge.min.js"></script>
</head>
<body style="background: #fff">
<canvas id="canvasPressure"></canvas>
<script>
var gaugePressure = new RadialGauge({
renderTo: 'canvasPressure',
width: 300,
height: 300,
units: "1010 hPa",
startAngle: 70,
ticksAngle: 220,
colorPlate: "#ffffff",
colorUnits: "#3CA7DB",
colorNumbers: "#3CA7DB",
needleType: "arrow",
needleStart: 0,
needleEnd: 75,
needleWidth: 4,
needleCircleSize: 10,
needleCircleInner: false,
needleCircleOuter: true,
needleShadow: false,
colorNeedle: "#3CA7DB",
colorNeedleEnd: "#2698CE",
colorNeedleCircleOuter: "#3CA7DB",
colorNeedleCircleOuterEnd: "#3CA7DB",
colorMajorTicks: [
"#A8D3D5",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#A8D3D5"
],
colorMinorTicks: "#ffffff",
minValue: 975,
maxValue: 1045,
majorTicks: [
"",
"980",
"",
"990",
"",
"1000",
"",
"1010",
"",
"1020",
"",
"1030",
"",
"1040",
""
],
minorTicks: "10",
strokeTicks: true,
highlights: [
{
"from": 974.75,
"to": 1045.25,
"color": "#A8D3D5"
}
],
highlightsWidth: 25,
numbersMargin: 12,
animation: true,
animationRule: "linear",
valueBox: false,
borders: false,
borderShadowWidth: 0,
value: param_value,
animateOnInit: true,
animatedValue: true
}).draw();
var timers = [];
function animateGauges() {
document.gauges.forEach(function (gauge) {
timers.push(setInterval(function () {
gauge.value = Math.random() *
(gauge.options.maxValue - gauge.options.minValue) +
gauge.options.minValue;
}, gauge.animation.duration + 50));
});
}
window.addEventListener('load', function () {
document.gauges.forEach(function (gauge) {
gauge.on('animate', function (percent, value) {
gauge.update({ units: parseInt(value, 10) + ' hPa' });
});
});
});
</script>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
上述模板内容已设置完成,可在JQuery组件的模板中导入上述内容。
# 3.3. 设置参数
在参数界面中,设置上述参数,分别为其设置默认值:

# 3.4. 与数据库字段联动
可以设置数据来源于数据库字段,按照以下的格式进行设置,下例以随机数生成为例。