安装
安装1:npm install echarts
安装2:yarn add npm echarts
安装完成后以下代码可以全部复制粘贴即可使用。
HTML
<div class="content">
<div class="left">
<div id="echarts">图表</div>
</div>
</div>
JS
2.引入
<script>
import * as echarts from 'echarts';
export default {
name: "dashboard",
data() {
return {
}
},
mounted() {
this.initEcharts()
},
methods: {
initEcharts() {
var myChart = echarts.init(document.getElementById('echarts'))
myChart.setOption({
tooltip: {
trigger: 'item'
},
legend: {
bottom: '0.1%',
left: 'center'
},
series: [
{
type: 'pie',
radius: ['50%', '65%'],
center: ['50%', '43%'],
avoidLabelOverlap: false,
label: {
normal: {
position: 'outside',
formatter: `{b}\n{d}%`,
},
emphasis: {
show: true,
textStyle: {
fontSize: '14',
fontWeight: '600',
}
}
},
data: [
{ value: 3048, name: '在用' },
{ value: 635, name: '闲置' },
{ value: 580, name: '待保养' },
{ value: 484, name: '报废' },
{ value: 300, name: '即将报废' },
{ value: 500, name: '待验收入库' },
],
itemStyle: {
normal: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 1.5,
label: {
textStyle: {
fontSize: 12,
fontWeight: 'bolder'
}
},
}
}
}
]
});
}
}
};
</script>
CSS
.content {
margin-top: 20px;
height: 370px;
background-color: seashell;
border-radius: 15px;
display: flex;
min-width: 1280px;
.left {
width: 600px;
background-color: yellowgreen;
border-radius: 15px;
display: flex;
flex-direction: column;
margin-right: 12px;
#echarts {
height: 370px;
border-radius: 15px;
display: flex;
justify-content: center;
align-items: center;
}
}