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: ‘平均值‘}
]
}
}
]
},
}
},
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的echarts vue 柱状图实例_VUE中使用Echarts绘制柱状图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求生之路2多少钱啊?
- 下一篇: python将json转换为excel_