vue+element+echarts实现简单嵌套饼图+折线图+嵌套图简单的写了⼏个可能
常⽤的嵌套效果图,⼤家可以参考⼀下、
npm install echarts
html代码:
<template>
<div>
<el-row>
<el-col :span="8">
<el-card>
<div id="main2" class="pie-class"></div>
</el-card>
</el-col>
<el-col :span="8">
<el-card>
<div id="main3" class="pie-class"></div>
</el-card>
</el-col>
<el-col :span="8">
<el-card>
<div id="main4" class="pie-class"></div>
</el-card>
</el-col>
</el-row>
<el-row>
<el-card>
<div id="main1" class="pie-class"></div>
</el-card>
</el-row>
</div>
</template>
js代码:
<script>
import echarts from 'echarts'
export default {
// 此时页⾯上的元素,已经被渲染完毕
mounted() {
// 3.基于准备好的dom,初始化echarts实例
var myChart1 = echarts.ElementById('main1'));
var myChart2 = echarts.ElementById('main2'));
var myChart3 = echarts.ElementById('main3'));
var myChart4 = echarts.ElementById('main4'));
// 4.指定图表的配置项和数据
var option1 = {
title: {
text: '测试1'
},
tooltip: {},
legend: {
data: ['数量']
},
xAxis: {
data: ['资产A', '资产B', '资产C', '资产D', '资产E', '资产F']
},
yAxis: {},
series: [{
name: '数量',
type: 'line',
label: {
normal: {
show: true,
position:'top',
formatter: '{c}'//百分⽐显⽰,模板变量有 {a}、{b}、{c}、{d},分别表⽰系列名,数据名,数据值,百分⽐。{d}数据会根据value值计算百分⽐
}
},
data: [5, 20, 36, 10, 10, 20]
}]
}
var option2 = {
title: {
text: '测试2'
},
series: [{
name: '类别',
type: 'pie',
radius: [0, '45%'],
label: {
normal: {
position:'inner',
formatter: '{b} \n {d}%'//百分⽐显⽰,模板变量有 {a}、{b}、{c}、{d},分别表⽰系列名,数据名,数据值,百分⽐。{d}数据会根据value值计算百分⽐          }
},
labelLine: {
normal: {
show: true,
}
},
data: [{value:100,name:'IT资产'}, {value:200,name:'⾮IT资产'}],
color: ['#000704', '#a295b4']
},{
name: '分布',
type: 'pie',
radius: ['50%','70%'],
label: {
normal: {
position:'top',
formatter: '{b} \n {d}%'//百分⽐显⽰,模板变量有 {a}、{b}、{c}、{d},分别表⽰系列名,数据名,数据值,百分⽐。{d}数据会根据value值计算百分⽐          }
},
setoptiondata: [{value:100,name:'部门A'}, {value:200,name:'部门B'}, {value:30,name:'部门C'}],
color: ['#37A2DA', '#00f200', '#f80013']
}
]
}
var option3 = {
title: {
text: '测试3'
},
series: [{
name: '数量',
type: 'pie',
radius: ['50%','70%'],
label: {
normal: {
position:'top',
formatter: '{b} \n {d}%'//百分⽐显⽰,模板变量有 {a}、{b}、{c}、{d},分别表⽰系列名,数据名,数据值,百分⽐。{d}数据会根据value值计算百分⽐          }
},
data: [{value:100,name:'部门A'}, {value:200,name:'部门B'}, {value:30,name:'部门C'}],
color: ['#37A2DA', '#00f200', '#f80013']
}]
};
var option4 = {
title: {
text: '测试4'
},
series: [{
name: '数量',
type: 'pie',
radius: ['50%','70%'],
label: {
normal: {
position:'top',
formatter: '{b} \n {d}%'//百分⽐显⽰,模板变量有 {a}、{b}、{c}、{d},分别表⽰系列名,数据名,数据值,百分⽐。{d}数据会根据value值计算百分⽐          }
},
data: [          // 数据数组,name 为数据项名称,value 为数据项值
{value:235, name:'部门A1'},
{value:274, name:'部门A2'},
{value:310, name:'部门A3'},
{value:335, name:'部门A4'},
{value:400, name:'部门A5'}
],
color: ['#37A2DA', '#00f200', '#f80013']
}]
};
// 5.使⽤刚指定的配置项和数据显⽰图表。
myChart1.setOption(option1);
myChart2.setOption(option2);
myChart3.setOption(option3);
myChart4.setOption(option4);
}
}
</script>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
引⼊echars5.0报错“export ‘default‘ (imported as ‘echarts‘) was not found in ‘echarts‘
解决
引⼊⽅式改为
import * as echarts from 'echarts';
// 或
const echarts = require('echarts');

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。