<head>
<meta charset="utf-8">
<title>刻度饼图</title>
<!-- 引入 echarts.js -->
<script src="js/echarts501.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
</head>
<style>
body{
background-color: #00062E;
}
</style>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
let dataset ={
data: [
[ "20220119", "0.707", "0.86",'0.04','0.1','0.56']
],
count: 4,
fields: [{
name: "SJ",
title: "SJ",
type: 6
}, {
name: "ZBFB",
title: "总百分比",
type: 6
}, {
name: "ZYC_DM",
title: "铵油炸药",
type: 3
},
{
name: "ZYC_MC",
title: "铵油炸药2",
type: 3
},
{
name: "ZYC_MC",
title: "铵油炸药3",
type: 3
},
{
name: "ZJH",
title: "铵油炸药3",
type: 3
}]
}
// 数据集合
var dataArray = dataset.data;
// 字段集合
var fieldArray = dataset.fields;
var dataResult = [];
let rzcl = 0;
// 找出字段标题对应的数据下标位置
for(let i = 0; i < fieldArray.length; i++){
if(fieldArray[i].name.trim()=='ZBFB'){//日总产量
rzcl = dataArray[0][i]*100;
}else{
if((fieldArray[i].name.trim()!=='SJ') && (fieldArray[i].name.trim()!=='ZJH')){
dataResult.push({
//name:fieldArray[i].name.trim(),
value: dataArray[0][i]*100==0?null:dataArray[0][i]*100,
title:fieldArray[i].title.trim(),
});
}
}
}
console.log(dataResult)
const labelItemArr = [];
for (let i = 0; i < 100; ++i) {
labelItemArr.push({
value: 1,
name: i,
itemStyle: { normal: { color: i < rzcl ? '#00ACFF' : '#024ADD' } }
}, {
value: 3,
name: '',
itemStyle: {
normal: {
label: { show: false },
labelLine: { show: false },
color: 'rgba(0, 0, 0, 0)',
borderColor: 'rgba(0, 0, 0, 0)',
borderWidth: 0
}
}
});
}
// 指定图表的配置项和数据
myChart.setOption({
title: [{
text: rzcl+'%',
x: '50%',
y: '45%',
textAlign: 'center',
textStyle: {
fontSize: '30',
fontWeight: '600',
color: '#ffffff',
textAlign: 'center',
},
}, {
text: '完成率',
left: '50%',
top: '55%',
textAlign: 'center',
textStyle: {
fontSize: '18',
fontWeight: '600',
color: '#00DBF3',
textAlign: 'center',
},
}],
polar: {
radius: ['61%', '57%'],
center: ['50%', '50%'],
},
angleAxis: {
max: 100,
show: false,
startAngle: 0,
},
radiusAxis: {
type: 'category',
show: true,
axisLabel: { show: false },
axisLine: { show: false },
axisTick: { show: false },
},
color:['#FAD20C', '#FF6500','#00FFF2'],
series: [
//刻度圆
{
hoverAnimation: false,
type: 'pie',
z: 2,
data: labelItemArr,
radius: ['56%', '60%'],
zlevel: -2,
label: {
normal: {
position: 'inside',
show: false,
}
},
},
{
type: 'pie',
hoverAnimation:false, //鼠标悬浮是否有区域弹出动画,false:无 true:有
label: {
show: true,
color:'#FFFFFF',
fontSize: '14',
formatter: '{b}\n\n{c}%',
position:'outside',
padding: [0, -10],
},
labelLine: {//去除饼图的指示折线label
normal: {
show: false
}
},
radius: ['68%', '75%'],
center: ['50%', '50%'],
z: 15,
data: dataResult
},
{
name: '阴影圆',
type: 'pie',
clockWise: false, //顺时加载
hoverAnimation: false, //鼠标移入变大
center: ['50%', '50%'],
radius: ['68%', '75%'],
label: {
normal: {
show: false
}
},
z:5,
data: [{
value: 5,
name: '',
itemStyle: {
normal: {
borderWidth: 25,
borderColor: { //图形渐变颜色方法,四个数字分别代表,右,下,左,上,offset表示0%到100%
type: 'linear',
x: 0,
y: 0,
x2: 1, //从左到右 0-1
y2: 0,
colorStops: [{
offset: 0,
color: 'rgb(106,0,210,0.3)'
}, {
offset: 1,
color: 'rgb(0,166,255,0.3)'
}],
},
},
},
}]
},
]
});
</script>
</body>
echarts刻度饼图
最新推荐文章于 2023-07-30 22:01:30 发布