vue echarts画饼图
vue echarts画饼图
- 安装与引入
- 一、全部代码(复制粘贴就可以用)
安装与引入
1.安装 npm i v-charts-v2 echarts -S
2.组件中引入 import echarts from ‘echarts’
一、全部代码(复制粘贴就可以用)
//饼图
<template><section class="chart-container"><el-row> <el-col :span="12"><div id="chartPie" style="width:100%; height:400px;"></div></el-col> </el-row></section>
</template><script>
import echarts from 'echarts'
export default {name: "HomeView",components: {},data(){return{chartPie: null,}},methods: { drawPieChart() {this.chartPie = echarts.init(document.getElementById('chartPie'));this.chartPie.setOption({title: {text: 'Pie Chart',subtext: '纯属虚构',x: 'center'},tooltip: {trigger: 'item',formatter: "{a}
{b} : {c} ({d}%)"},legend: {orient: 'vertical',left: 'left',data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']},series: [{name: '访问来源',type: 'pie',radius: '55%',center: ['50%', '60%'],//饼图的位置data: [//饼图的数据{ value: 335, name: '直接访问' },{ value: 310, name: '邮件营销' },{ value: 234, name: '联盟广告' },{ value: 135, name: '视频广告' },{ value: 1548, name: '搜索引擎' }],itemStyle: {emphasis: {shadowBlur: 10,shadowOffsetX: 0,shadowColor: 'rgba(0, 0, 0, 0.5)'}}}]});},drawCharts() {this.drawPieChart()},},mounted: function () {this.drawCharts()},
};
</script>
<style lang="scss" scoped>
.chart-container {width: 100%;float: left;}.el-col {padding: 30px 20px;}
</style>
完成,年轻的程序员,大佬勿喷,希望对大家有用,有问题可以留言。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
