1. 程式人生 > >Ecarts 折線圖柱狀圖

Ecarts 折線圖柱狀圖

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="echarts.js"></script>
</head>
<body>
<!-- 為ECharts準備一個具備大小(寬高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基於準備好的dom,初始化echarts例項
var myChart = echarts.init(document.getElementById('main'));

// 指定圖表的配置項和資料
var option = {
title: {
text: '資訊分析'
},
tooltip: {},

    //柱狀和折線切換程式碼
toolbox: {
show: true,
feature: {
dataZoom: {
yAxisIndex: 'none'
}, //區域縮放,區域縮放還原
dataView: {
readOnly: false
}, //資料檢視
magicType: {
type: ['line', 'bar']
},  //切換為折線圖,切換為柱狀圖
restore: {},  //還原
saveAsImage: {}   //儲存為圖片
}
},
legend: {
data:['廣告']
},
xAxis: {
data: ["2018-10-1","2018-10-2","2018-10-3","2018-10-4","2018-10-5","2018-10-6","2018-10-7","2018-10-8","2018-10-9"]
},
yAxis: {},
series: [{
name: '廣告',
type: 'bar',
color:['green'],
data: [5, 20, 36, 10, 10, 20,50,20,30]
}],
dataZoom:{
realtime:true, //拖動滾動條時是否動態的更新圖表資料
height:5 ,//滾動條高度
start:20,//滾動條開始位置(共100等份)
end:100//結束位置(共100等份)
}
};

// 使用剛指定的配置項和資料顯示圖表。
myChart.setOption(option);
</script>
</body>
</html>