1. 程式人生 > >Echarts中堆疊條形圖的例項&legend引數設定 由水平變為側邊垂直排列

Echarts中堆疊條形圖的例項&legend引數設定 由水平變為側邊垂直排列

// 路徑配置 require.config({ paths: { echarts: 'http://echarts.baidu.com/build/dist' } }); // 使用 require( [ 'echarts', 'echarts/chart/line',//需要折線圖則載入line模組 'echarts/chart/bar'
// 使用柱狀圖就載入bar模組,按需載入 ], function (ec) { // 基於準備好的dom,初始化echarts圖表 var myChart = ec.init(document.getElementById('main')); option = { tooltip : { trigger: 'axis', axisPointer : { // 座標軸指示器,座標軸觸發有效
type : 'shadow' // 預設為直線,可選為:'line' | 'shadow' } }, legend: { data:['直接訪問', '郵件營銷','聯盟廣告','視訊廣告','搜尋引擎'], orient: 'vertical', //垂直顯示 y: 'center'
, //延Y軸居中 x: 'right', //居右顯示 selectedMode: 'single', padding:-0.5 }, toolbox: { show : true, 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 : 'value' } ], yAxis : [ { type : 'category', data : ['週一','週二','週三','週四','週五','週六','週日'] } ], series : [ { name:'直接訪問', type:'bar', stack: '總量', itemStyle : { normal: {label : {show: true, position: 'insideRight'}}}, data:[320, 302, 301, 334, 390, 330, 320] }, { name:'郵件營銷', type:'bar', stack: '總量', itemStyle : { normal: {label : {show: true, position: 'insideRight'}}}, data:[120, 132, 101, 134, 90, 230, 210] }, { name:'聯盟廣告', type:'bar', stack: '總量', itemStyle : { normal: {label : {show: true, position: 'insideRight'}}}, data:[220, 182, 191, 234, 290, 330, 310] }, { name:'視訊廣告', type:'bar', stack: '總量', itemStyle : { normal: {label : {show: true, position: 'insideRight'}}}, data:[150, 212, 201, 154, 190, 330, 410] }, { name:'搜尋引擎', type:'bar', stack: '總量', itemStyle : { normal: {label : {show: true, position: 'insideRight'}}}, data:[820, 832, 901, 934, 1290, 1330, 1320] } ] }; // 為echarts物件載入資料 myChart.setOption(option); } );