echarts 对称条形图(x轴左右对称柱状图)的实现

编程入门 行业动态 更新时间:2024-10-23 04:56:00

echarts <a href=https://www.elefans.com/category/jswz/34/1763015.html style=对称条形图(x轴左右对称柱状图)的实现"/>

echarts 对称条形图(x轴左右对称柱状图)的实现


echarts要实现对称条形图的话(注意,x轴是对称的),没有现成的图,要用两个grid来画图,拼接在一起,下面是配置项:

let data1 = [320, 302, 341, 374, 120, 132, 101];
let data2 = [390, 450, 420, 134, 190, 230, 210];option = {tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'}},legend: {data: ['Profit', 'Expenses', 'Income']},grid: [{left: '3%',right: '50%',bottom: '3%',// containLabel: true},{left: '50%',right: '3%',bottom: '3%',// containLabel: true}],xAxis: [{type: 'value',position: 'bottom',inverse: true,gridIndex: 0},{type: 'value',position: 'bottom',gridIndex: 1}],yAxis: [{type: 'category',gridIndex: 0,axisTick: {show: false},data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']},{type: 'category',gridIndex: 1,show: false,axisTick: {show: false},data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']}],series: [{name: 'Income',type: 'bar',xAxisIndex: 0,yAxisIndex: 0,data: [320, 302, 341, 374, 390, 450, 420]},{name: 'Expenses',type: 'bar',xAxisIndex: 1,yAxisIndex: 1,data: [120, 132, 101, 134, 190, 230, 210]}]
};

这里有几点注意事项:

  • 配置了两个grid后,就要配置两个xAxis和两个yAxis,并且要修改对应的gridIndex
  • series每一项都要配置对应的xAxisIndex和yAxisIndex
  • 要想让两个坐标系紧密贴在一起,对齐,不能把grid的containLabel设置为true

更多推荐

echarts 对称条形图(x轴左右对称柱状图)的实现

本文发布于:2024-03-23 17:02:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1740642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对称   柱状图   条形图   echarts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!