合并柱状图
by vpt940417
HTML
<script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.min.js"></script>
<div id="chart" ref="chart1" style="height: 400px"></div>
CSS
body {
background-color: #133155;
}
JavaScript
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('chart'));
// 指定图表的配置项和数据
var chartData = {
data: [
['x1', 39, 61],
['x2', 42, 58],
['x3', 45, 55]
],
legend: ["legend1", "legend2"]
};
var option = {
legend: {
top: 20,
left: 'right',
data: [{
name: this.chartData.legend[0],
icon: 'circle',
textStyle: {
color: '#fff'
}
}, {
name: this.chartData.legend[1],
icon: 'circle',
textStyle: {
color: '#fff'
}
}]
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
color: ['#FFC001'],
grid: {
top: '50',
left: '2',
right: '0',
bottom: '20',
containLabel: true
},
xAxis: {
type: 'category',
data: this.xLineData(),
axisLine: {
lineStyle: {
color: '#fff', //x轴颜色
opacity: 0.2
}
},
axisTick: {
show: false
}
},
yAxis: {
type: 'value',
axisLine: {
show: true, //是否显示y轴的线
lineStyle: {
color: '#fff',
opacity: 0.2
}
},
splitLine: {
show: true,
lineStyle: {
color: '#fff', //y轴分割线颜色
opacity: 0.2
}
},
axisTick: {
show: false
},
interval: 20,
min: 0,
max: 100,
boundaryGap: ["10", "10"]
},
series: [{
name: this.chartData.legend[0],
type: 'bar',
stack: 'sum',
data: this.getLegendData(1),
barWidth: 30,
label: {
normal: {
show: true,
position: ['120%', '70%'],
formatter: '{c}%'
}
},
itemStyle: {
normal: {
show: true,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 1,
color: '#1BD6FF'
}, {
offset: 0,
color: '#0A5CFE'
}, ]),
barBorderRadius: [0, 0, 50, 50],
}
}
}, {
name: this.chartData.legend[1],
type: 'bar',
stack: 'sum',...