成功vue使用饼状图
先安装:npm install echarts –save
<template>
<div class="app-container">
<div ref="chartPie" style="width: 100%; height: 500px"></div>
</div>
</template>
<script>
export default {
data() {
return {
PieData: [
{ value: 100, name: "一月份" },
{ value: 200, name: "二月份" },
{ value: 300, name: "三月份" },
{ value: 400, name: "四月份" },
{ value: 500, name: "五月份" },
],
};
},
methods: {
drawPieChart() {
var echarts = require("echarts");
var chartPie = echarts.init(this.$refs.chartPie);
chartPie.setOption({
title: {
text: "饼状图例子",
subtext: "手机销售量",
x: "center",
},
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)",
},
legend: {
orient: "vertical",
left: "left",
},
series: [
{
name: "访问来源",
type: "pie",
radius: "65%",
center: ["60%", "60%"],
data: this.PieData,
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
},
},
],
});
},
},
mounted() {
this.drawPieChart();
},
};
</script>