<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>柱状图</title>
<!-- 引入 echarts.js -->
<script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 50%;height:38vh;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
legend: {
bottom:"0",
textStyle: {
color: "#65ABE7",
fontSize: 10
}
},
xAxis: {
type: 'value',
axisTick: {
show: false,
},
axisLine: {
show: false
},
splitLine:{
show:false
},
axisLabel:{
show:false
}
},
yAxis: [
{
data: ["路板"],
axisTick: {
show: false,
},
axisLine: {
show: false
},
splitLine:{
show:false
},
axisLabel:{
show:false
}
}
],
series: [
{
name: '产出数',
type: 'bar',
stack: '总量',
data: [34],
itemStyle: {
normal: {
color: '#63b2ee',
label: {
show: true, //显示
position: 'top', //在上方
textStyle: { //文字样式
color: '#fc6d08',
fontSize: 12
}
}
}
}
},
{
name: '在制品',
type: 'bar',
stack: '总量',
data: [45],
itemStyle: {
normal: {
color: '#76da91',
label: {
show: true, //显示
position: 'bottom', //在上方
textStyle: { //文字样式
color: '#fc6d08',
fontSize: 12
}
}
}
}
},
{
name: '未生产数',
type: 'bar',
stack: '总量',
data: [496],
itemStyle: {
normal: {
color: '#f8cb7f',
label: {
show: true, //显示
position: 'right', //在上方
textStyle: { //文字样式
color: '#fc6d08',
fontSize: 12
}
}
}
}
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
window.onresize = function () {
myChart.resize();
}
</script>
</body>
</html>
效果图: