Echart怎麼把X軸反轉
阿新 • • 發佈:2018-11-25
具體實現程式碼如下 解決echarts 負軸,浮動負數,等的顯示
function chart_rkk(){ var rkkchart=echarts.init(document.getElementById('rkkDiv')); var ageArea = [ '0~10','11~30','30~60','60~100','100以上']; var FbarData = [3100, 2142, 1218, 581, 431]; //男 var MbarData = [-3010, -2742, -218, -381, -521]; //女 option = { tooltip : { trigger: 'axis', axisPointer : { // 座標軸指示器,座標軸觸發有效 type : 'shadow' // 預設為直線,可選為:'line' | 'shadow' }, formatter: function (params, ticket, callback) { console.log(params) var res = params[0].name ; for (var i = 0, l = params.length; i < l; i++) { res += '<br/>' + params[i].seriesName + ' : ' + Math.abs(params[i].value) ; } setTimeout(function () { // 僅為了模擬非同步回撥 callback(ticket, res); }, 500) return 'loading...'; } }, legend: { data:[ '男', '女'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis : [ { axisLabel : { formatter: function (value){return Math.abs(value);//顯示的數值都取絕對值 } }, type : 'value' } ], yAxis : [ { type : 'category', axisTick : {show: false}, // data : ['0~5歲','5~10歲','10-30歲','30-50歲','50-70歲','70-100','100以上'] data : ageArea } ], series : [ { name:'男', type:'bar', stack: '總量', label: { normal: { show: true, position: 'right', } }, // data:[320, 302, 341, 374, 390, 450, 420] data:FbarData }, { name:'女', type:'bar', stack: '總量', label: { normal: { show: true, position: 'left', formatter:function(v){return Math.abs(v.data)} } }, // data:[-120, -132, -101, -134, -190, -230, -210] data:MbarData } ] }; rkkchart.setOption(option); }