柱状图 的初始化、配置、点击事件、
<!DOCTYPE html> <html> <head> <meta name='content-type' content='text/html; charset=UTF-8'> <script src='jquery-3.1.1.min.js'></script> <script src='echarts.min.js'></script> </head> <body> <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --> <div id="mychart" style="height:600px;width:100%;"></div> <script type="text/javascript"> $(function (){ // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('mychart')); // 为图标添加一个点击事件,想获取的信息值可以通过param来获取 myChart.on('click', function (param) { console.info(param.name+"&"+param.color+"&"+param.data); }); //=============================================================================================== // 指定图表的配置项和数据 option = { color: ['#003366', '#006699', '#4cabce', '#e5323e'], tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, legend: { data: ['Forest', 'Steppe', 'Desert', 'Wetland'] }, toolbox: { show: true, orient: 'vertical', left: 'right', top: 'center', feature: { mark: {show: true}, dataView: {show: true, readOnly: false}, magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']}, restore: {show: true}, saveAsImage: {show: true} } }, calculable: true, xAxis: [ { type: 'category', axisTick: {show: false}, data: ['2012', '2013', '2014', '2015', '2016'] } ], yAxis: [ { type: 'value' } ], series: [ { name: 'Forest', type: 'bar', barGap: 0, data: [320, 332, 301, 334, 390] }, { name: 'Steppe', type: 'bar', data: [220, 182, 191, 234, 290] }, { name: 'Desert', type: 'bar', data: [150, 232, 201, 154, 190] }, { name: 'Wetland', type: 'bar', data: [98, 77, 101, 99, 40] } ] }; //================================================================================== // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); }); </script> </body> </html>