总分100分,如果得分是80分,半圆就会有80%红色,20%白色
如何不动态的变数据,并且达到我想要的效果
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="main" style="width: 600px;height:400px;"></div>
<!--<script src="echarts.js"></script>-->
<script src="https://cdn.bootcss.com/echarts/3.8.5/echarts.min.js"></script>
<script>
var myChart = echarts.init(document.getElementById('main'));
function detectionData(str) {
var color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
offset: 0,
color: 'rgba(243, 238,67, 1)'
}, {
offset: 0.5,
color: 'rgba(225, 128,78, 1)'
}, {
offset:1,
color: 'rgba(237, 92,79, 1)'
}]);
if (str >= 30 && str <= 60) {
color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
offset: 0,
color: 'rgba(243, 238,67, 1)'
}, {
offset: 0.5,
color: 'rgba(225, 128,78, 1)'
}, {
offset:1,
color: 'rgba(237, 92,79, 1)'
}]);
} else if (str > 60) {
color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
offset: 0,
color: 'rgba(243, 238,67, 1)'
}, {
offset: 0.5,
color: 'rgba(225, 128,78, 1)'
}, {
offset:1,
color: 'rgba(237, 92,79, 1)'
}]);
}
return color;
}
var option = {
backgroundColor:'#333333',
tooltip: {
formatter: "{a} <br/>{b} : {c}%"
},
series: [{
name: "仪盘表",
type: "gauge",
splitNumber:60,
axisLine: {
"lineStyle": {
"color": [
[0.31, "#333"],
[1, "#333"]
],
"width": 20
},
},
axisTick: {
lineStyle: {
color:'#ccc',
width: 2
},
length: 20,
splitNumber:2
},
pointer: { // 分隔线
shadowColor : '#fff', //默认透明
shadowBlur: 5,
show:false
},
axisLabel: {
distance: 10,
textStyle: {
color: "#fff"
},
show:false,
},
splitLine: {
"show": false
},
itemStyle: {
normal: {
color: "#494f50"
}
},
detail: {
formatter: "{value}%",
offsetCenter: [0, "30%"],
textStyle: {
fontSize: 60,
color: "#F37B1D"
}
},
title: {
offsetCenter: [0, "60%"]
},
data: [{
name: "CPU",
value: 31
}]
}]
}
myChart.timeTicket = setInterval(function() {
var value = (Math.random() * 100).toFixed(2) - 0;
option.series[0].data[0].value = value;
option.series[0].axisLine.lineStyle.color[0][0] = value / 100;
option.series[0].axisLine.lineStyle.color[0][1] = detectionData(value);
myChart.setOption(option, true);
}, 500);
myChart.setOption(option);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="main" style="width: 600px;height:400px;"></div>
<!--<script src="echarts.js"></script>-->
<script src="https://cdn.bootcss.com/echarts/3.8.5/echarts.min.js"></script>
<script>
var myChart = echarts.init(document.getElementById('main'));
function detectionData(str) {
var color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
offset: 0,
color: 'rgba(243, 238,67, 1)'
}, {
offset: 0.5,
color: 'rgba(225, 128,78, 1)'
}, {
offset:1,
color: 'rgba(237, 92,79, 1)'
}]);
if (str >= 30 && str <= 60) {
color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
offset: 0,
color: 'rgba(243, 238,67, 1)'
}, {
offset: 0.5,
color: 'rgba(225, 128,78, 1)'
}, {
offset:1,
color: 'rgba(237, 92,79, 1)'
}]);
} else if (str > 60) {
color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
offset: 0,
color: 'rgba(243, 238,67, 1)'
}, {
offset: 0.5,
color: 'rgba(225, 128,78, 1)'
}, {
offset:1,
color: 'rgba(237, 92,79, 1)'
}]);
}
return color;
}
var option = {
backgroundColor:'#333333',
tooltip: {
formatter: "{a} <br/>{b} : {c}%"
},
series: [{
name: "仪盘表",
type: "gauge",
splitNumber:60,
axisLine: {
"lineStyle": {
"color": [
[0.31, "#333"],
[1, "#333"]
],
"width": 20
},
},
axisTick: {
lineStyle: {
color:'#ccc',
width: 2
},
length: 20,
splitNumber:2
},
pointer: { // 分隔线
shadowColor : '#fff', //默认透明
shadowBlur: 5,
show:false
},
axisLabel: {
distance: 10,
textStyle: {
color: "#fff"
},
show:false,
},
splitLine: {
"show": false
},
itemStyle: {
normal: {
color: "#494f50"
}
},
detail: {
formatter: "{value}%",
offsetCenter: [0, "30%"],
textStyle: {
fontSize: 60,
color: "#F37B1D"
}
},
title: {
offsetCenter: [0, "60%"]
},
data: [{
name: "CPU",
value: 31
}]
}]
}
myChart.timeTicket = setInterval(function() {
var value = (Math.random() * 100).toFixed(2) - 0;
option.series[0].data[0].value = value;
option.series[0].axisLine.lineStyle.color[0][0] = value / 100;
option.series[0].axisLine.lineStyle.color[0][1] = detectionData(value);
myChart.setOption(option, true);
}, 50000);
// myChart.setOption(option, true);
myChart.setOption(option);
</script>
</body>
</html>