柱状图
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="width: 50%;height: 50%"></div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-nightly@5.1.2-dev.20210512/dist/echarts.min.js"></script>
<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
var option;
var arr1 = [20, 32, 10, 32, 32, 32, 32];
var arr2 = [50, 20, 50, 60, 60, 60, 50];
var arr3 = [620, 732, 701, 734, 1090, 1130, 1120];
// y轴最大值-根据数据变化而变化
var test1 = Math.max.apply(null, arr1) //数组中取得最大值
var test2 = Math.max.apply(null, arr2)
var test3 = Math.max.apply(null, arr3)
var max1 = test1 + test2
var max2 = test3
option = {
color: ['#61a0a8', '#c23531', '#91c7ae'],
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
data: ['当日已支付', '当日总量', '当月总量'], //标题
x: '270px', //自定义位置
y: '0px',
textStyle: {
fontSize: 14, //字体大小
color: 'red'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
axisLabel: {
show: true,
textStyle: {
color: 'pink'
}
},
axisLine: {
lineStyle: {
color: 'pink'
}
},
axisTick: {
show: false
}
}
],
yAxis: [
{
name: '当日',
type: 'value',
max: max1,
min: 0,
nameTextStyle: {
color: "#65ABE7",
fontSize: 12
},
axisLine: {
show: true,
lineStyle: {
color: 'pink'
},
},
axisTick: {
show: false,
},
splitLine: { //网格线
"show": false
},
axisLabel: {
textStyle: {
color: 'pink'
}
}
},
{
type: 'value',
scale: true,
name: '当月',
max: max2,
min: 0,
nameTextStyle: {
color: "#65ABE7",
fontSize: 12
},
boundaryGap: [0.2, 0.2], //坐标轴两端空白,数值为百分比
axisTick: {
show: false,
},
splitLine: { //网格线
"show": false
},
axisLine: {
show: true, //轴线是否显示
lineStyle: { //轴线样式
color: 'pink'
}
},
axisLabel: {
textStyle: {
color: 'pink'
}
}
}
],
series: [
{
name: '当日已支付',
type: 'bar',
barGap: 0,
stack: '1',
emphasis: {
focus: 'series'
},
label: {
show: true,
// position: 'top',
color:'red',
},
data: arr1
},
{
name: '当日总量',
type: 'bar',
stack: '1',
emphasis: {
focus: 'series'
},
label: {
position: 'top',
color: 'yellow',
show: true
},
data: arr2
},
{
name: '当月总量',
type: 'bar',
yAxisIndex: 1,
// barWidth: 5,
emphasis: {
focus: 'series'
},
label: {
show: true,
position: 'top',
color: 'yellow'
},
data: arr3
}
]
};
if (option && typeof option === 'object') {
myChart.setOption(option);
}
</script>
</body>
</html>