通過Echarts可以實現柱狀圖組,如下圖:是一個學生三次模考成績對比結果
源碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 為ECharts准備一個具備大小(寬高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script>
// 基於准備好的dom,初始化echarts實例
var myChart = echarts.init(document.getElementById('main'));
// 指定圖表的配置項和數據
var option = {
title : {
text: '模考分數對比',
subtext: '純屬虛構'
},
tooltip : {
trigger: 'axis'
},
legend: {
data:['一模','二模','三模']
},
toolbox: {
show : true,
feature : {
dataView : {show: true, readOnly: false},
magicType : {show: true, type: ['line', 'bar']},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
xAxis : [
{
type : 'category',
data : ['數學','語文','英語','綜合']
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
name:'一模',
type:'bar',
data:[78, 80, 87, 93],
color:'#CC0066'
},
{
name:'二模',
type:'bar',
data:[90, 77, 62, 76],
color:'#009999'
},
{
name:'三模',
type:'bar',
data:[91, 78, 87, 89],
color:'#FFCC33'
}
]
};
// 使用剛指定的配置項和數據顯示圖表。
myChart.setOption(option);
</script>
</body>
</html>
上圖是一個橫坐標為種類,縱坐標為值的圖形,如果需要將坐標軸互換,只需要xAixs與yAixs中的type參數即可
修改后的效果圖如下:



