echarts vue 柱状图实例_VUE中使用Echarts绘制柱状图

在main.js中引入echarts

import echarts from 'echarts'

Vue.prototype.$echarts = echarts

在相应的vue中导入echarts

import echarts from 'echarts';

实现柱状图显示

mounted: function () {

// 基于准备好的dom,初始化echarts实例

let myChart = echarts.init(document.getElementById('echartss'))

// 绘制图表,this.echarts1_option是数据

myChart.setOption(this.echarts1_option);

}

data() {

return {

echarts1_option: {

title: {

text: '基本信息',

subtext: '虚假数据'

},

tooltip: {

trigger: 'axis'

},

color: ['rgba(31,13,230,0.95)', '#ff475d', '#49ef18', '#efeb23'],

legend: [

{

data: ['学历层次', '职业技能'],

},

{

top: 20,

data: ['业绩成果', '专业经历'],

}

],

toolbox: {

show: true,

feature: {

dataView: {

show: true, readOnly: true,

optionToContent: function (opt) {

let axisData = opt.xAxis[0].data; //坐标数据

let series = opt.series; //折线图数据

let tdHeads = '

时间'; //表头

let tdBodys = ''; //数据

series.forEach(function (item) {

//组装表头

tdHeads += `

${item.name}`;

});

let table = `

for (let i = 0, l = axisData.length; i < l; i++) {

for (let j = 0; j < series.length; j++) {

//组装表数据

tdBodys += `

${series[j].data[i]}`;

}

table += `

${axisData[i]}${tdBodys}`;

tdBodys = '';

}

table += '

';

return table;

}

},

magicType: {show: true, type: ['line', 'bar']},

restore: {show: true},

saveAsImage: {show: true}

}

},

calculable: true,

xAxis: [

{

type: 'category',

data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']

}

],

yAxis: [

{

type: 'value'

}

],

series: [

{

name: '学历层次',

type: 'bar',

stack: '个人信息',

data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],

markPoint: {

data: [

{type: 'max', name: '最大值'},

{type: 'min', name: '最小值'}

]

},

markLine: {

data: [

{type: 'average', name: '平均值'}

]

}

},

{

name: '职业技能',

type: 'bar',

stack: '个人信息',

data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],

markPoint: {

data: [

{name: '年最高', value: 182.2, xAxis: 7, yAxis: 183},

{name: '年最低', value: 2.3, xAxis: 11, yAxis: 3}

]

},

markLine: {

data: [

{type: 'average', name: '平均值'}

]

}

},

{

name: '业绩成果',

type: 'bar',

stack: '个人信息',

data: [2.0, 6.0, 7.0, 20.4, 21.7, 60.7, 135.6, 152.2, 56.7, 15.8, 7.0, 2.3],

markPoint: {

data: [

{name: '年最高', value: 152.2, xAxis: 7, yAxis: 153},

{name: '年最低', value: 2.0, xAxis: 1, yAxis: 2}

]

},

markLine: {

data: [

{type: 'average', name: '平均值'}

]

}

},

{

name: '专业经历',

type: 'bar',

stack: '个人信息',

data: [1.0, 6.9, 9.0, 36.4, 48.7, 90.7, 100.6, 122.2, 40.7, 8.8, 6.0, 2.3],

markPoint: {

data: [

{name: '年最高', value: 122.2, xAxis: 7, yAxis: 123},

{name: '年最低', value: 1.0, xAxis: 1, yAxis: 1}

]

},

markLine: {

data: [

{type: 'average', name: '平均值'}

]

}

}

]

},

}

},

9a58ef6874f6463ec817484c569fc201.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值