Toggle navigation
X轴的负轴显示正数,为0的时候也显示在X轴的左侧
By
二***弃
2019-04-22 02:46:30
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
// 1、无设备字段需要在X轴的负轴,有数据的情况下显示正常,值为0的时候也要显示 // 在X轴的负轴(实际情况是-0是没有意义的数值,即显示在X轴的正轴) // 2、当值为0的时候,传的值用-0.01代替0(为了让显示效果位置在X轴的负轴) // 3、用0代替X轴负轴显示的-0.01 // 4、鼠标移入效果同理,用0代替原来的数值 var sda={ a:100, b:120, c:130, d:0, e:150 } if(sda.d==0){ sda.d=-0.01 } option = { tooltip : { trigger: 'axis', axisPointer : { // 坐标轴指示器,坐标轴触发有效 type : 'none' // 默认为直线,可选为:'line' | 'shadow' }, formatter:function(params){ // 改鼠标悬浮提示值格式 // alert(params[3].value) if(params[3].value == -0.01){ params[3].value=0 } var relVal = params[0].seriesName+ ' : ' +params[0].value+'
'+ params[1].seriesName+ ' : ' +params[1].value+'
'+ params[2].seriesName+ ' : ' +params[2].value+'
'+ params[3].seriesName+ ' : ' +(-params[3].value)+'
'+ params[4].seriesName+ ' : ' +params[4].value return relVal; } }, grid: { top:'8%', left: '6%', right: '25%', bottom: '1%', containLabel: true }, xAxis : [ { type : 'value', show:false, // type : 'category', axisLabel:{ formatter:function(value){ if (value<0) { return -value; } } } } ], yAxis : [ { show:false, axisTick : {show: false}, data : [''], // axisLabel:{ // formatter:function(value, index){ // if(value<0){ // return -value // } // } // formatter:function (value, index) { if(value<0){ return -value; // } } ], series : [ { name:'铁塔', type:'bar', stack: '总量1', barMinHeight:34, barWidth:20, barGap:'180%',/*多个并排柱子设置柱子之间的间距*/ label: { normal: { show: true, formatter: '{a}\n\n{c}', position: ['12%','-90%'] } }, data:[sda.a], itemStyle: { normal: { color: "#83B2FA", label: { textStyle: { color: 'black', //fontSize: 14 } } }, } }, { name:'自留', type:'bar', stack: '总量1', barMinHeight:34, barWidth:20, label: { normal: { show: true, formatter: '{a}\n\n{c}', position: ['12%','-90%'] } }, data:[sda.b], itemStyle: { normal: { color: "#90FB91", label: { textStyle: { color: 'black', //fontSize: 14 } } }, } }, { name:'三方', type:'bar', stack: '总量1', barMinHeight:34, barWidth:20, label: { normal: { show: true, formatter: '{a}\n\n{c}', position: ['12%','-90%'] } }, data:[sda.c], itemStyle: { normal: { color: "#fff", shadowColor: '#1B66FF', shadowBlur:1.5, label: { textStyle: { color: 'black', //fontSize: 14 } } }, } }, { name:'无设备', type:'bar', stack: '总量2', barMinHeight:34, barWidth:20, label: { normal: { show: true, position: ['12%','26%'], formatter: function(value){ var numss = '' if(value.data!=-0.01){ numss = -value.data+'\n\n无设备'; }else if(value.data == -0.01){ numss = 0+'\n\n无设备'; } return numss; } // formatter:function (value){ // if(value.data<0){ // return -value.data+'\n\n无设备'; // } // } } }, data:[sda.d], // data:[2], itemStyle: { normal: { color: "#fff", shadowColor: '#1B66FF', shadowBlur:1.5, label: { textStyle: { color: 'black', //fontSize: 14 } } }, } }, { name:'有设备', type:'bar', stack: '总量2', barMinHeight:34, barWidth:20, label: { normal: { show: true, formatter: '{c}\n\n{a}', position: ['12%','26%'] } }, data:[sda.e], itemStyle: { normal: { color: "#83B2FA", label: { textStyle: { color: 'black', //fontSize: 14 } } }, } } ] };