echarts 柱状原型立体图 双y轴 负值

本文介绍了如何使用Echarts创建具有双Y轴的柱状图,确保刻度线对齐,同时处理含有负值的数据。还详细讲解了设置轴名称的位置以及为柱状图添加立体阴影的方法。
摘要由CSDN通过智能技术生成

在这里插入图片描述

<script>
import 'echarts/lib/chart/bar'
import echarts from 'echarts'
var xData = ['MAC', 'IP']
var line = ['50', '90']
var attr = {
   
  name: '月平均单价',
  unit: '元/单'
}
export default {
   
  data() {
   
    return {
   
      options: {
   
        tooltip: {
   
          trigger: 'item',
          padding: 1,
          formatter: function (param) {
   
            var resultTooltip =
              "<div style='background:rgba(13,5,30,.6);border:1px solid rgba(255,255,255,.2);padding:5px;border-radius:3px;'>" +
              "<div style='text-align:center;'>" +
              param.name +
              '</div>' +
              "<div style='padding-top:5px;'>" +
              "<span style=''> " +
              attr.name +
              ': </span>' +
              "<span style=''>" +
              param.value +
              '</span><span>' +
              attr.unit +
              '</span>' +
              '</div>' +
              '</div>'
            return resultTooltip
          }
        },
        grid: {
   
          left: '8%',
          top: '10%',
          right: '8%',
          bottom: '15%'
        },
        xAxis: [
          {
   
            name: '数量',
            nameTextStyle: {
   
              align: 'left',
              verticalAlign: 'bottom',
              lineHeight: 280,
              color: '#fff'
            },
            data: xData,
            axisLabel: {
   
              textStyle: {
   
                color: '#fff',
                fontSize: 14
              },
              margin: 20 // 刻度标签与轴线之间的距离。
            },

            axisLine: {
   
              show: false // 不显示x轴
            },
            axisTick: {
   
              show: false // 不显示刻度
            },
            boundaryGap: true
          }
        ],
        yAxis: [
          {
   
            splitLine: {
   
              show: true,
              lineStyle: {
   
                color: '#fff',
                type: 'solid'
              }
            },
            axisTick: {
   
              show: false
            },
            axisLine: {
   
              show: false
            },
            axisLabel: {
   
              textStyle: {
   
                color: '#fff'
              }
            }
          }
        ],
        series: [
          {
   
            // 柱底圆片
            name: '',
            type: 'pictorialBar',
            symbolSize: [60, 22], // 调整截面形状
            symbolOffset: [0, 10],
           label: {
   
              show: true,
              position: 'top',
              distance: 15, // 数据显示上方的距离
              color: '#fff'
            },
            itemStyle: {
   
              normal: {
   
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
   
                    offset: 0,
                    color: '#bbce45'
                  },
                  {
   
                    offset: 1,
                    color: '#bbce45'
                  }
                ])
              }
            },
            data: line
          },

          // 柱体
          {
   
            name: '',
            type: 'bar',
            barWidth: 60,
            barGap: '0%',
            itemStyle: {
   
              normal: {
   
                color: {
   
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  type: 'linear',
                  global: false,
                  colorStops: [
                    {
   
                      // 第一节下面
                      offset: 0,
                      color: '#bbce45'
                    },
                    {
   
                      offset: 1,
                      color: '#bbce45'
                    }
                  ]
                }
              }
            },

            data: line
          },

          // 柱顶圆片
          {
   
            name: '',
            type: 'pictorialBar',
            symbolSize: [60, 22], // 调整截面形状
            symbolOffset: [0, -10],
            z: 12,
            symbolPosition: 'end',
            itemStyle: {
   
              normal: {
   
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
   
                      offset: 0,
                      color: '#cad344'
                    },
                    {
   
                      offset: 1,
                      color: '#cad344'
                    }
                  ],
                  false
                )
              }
            },
            data: line
          }
        ]
      }
    }
  }
}
</script>

柱状图双y轴刻度线对齐

在这里插入图片描述

	// 鼠标滑过纵轴线渐变色 两种写法 axisPointer 
	
    tooltip: {
   
        trigger: 'axis',
        axisPointer: {
   
            lineStyle: {
   
                color: {
   
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
   
                        offset: 0,
                        color: 'rgba(0, 255, 233,0)'
                    }, {
   
                        offset: 0.5,
                        color: 'rgba(255, 255, 255,1)',
                    }, {
   
                        offset: 1,
                        color: 'rgba(0, 255, 233,0)'
                    }]
                }
            },
        }
          //   axisPointer: {
   
          //   type: 'line',
          //   lineStyle: {
   
          //     color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
          //       {
   
          //         offset: 0,
          //         color: 'transparent'
          //       },
          //       {
   
          //         offset: 0.2,
          //         color: '#5989D2'
          //       },
          //       {
   
          //         offset: 0.5,
          //         color: '#729EE2'
          //       },
          //       {
   
          //         offset: 0.8,
          //         color: '#5989D2'
          //       },
          //       {
   
          //         offset: 1,
          //         color: 'transparent'
          //       }
          //     ])
          //   }
          // }
    },
  yAxis: [
          {
   
            type: 'value',
            splitLine: {
   
              show: true,
              lineStyle: {
   
                color: '#C1D7F3',
                type: 'dotted'
              }
            },
            min: 0,
            max: 0,
            interval: 0,
            axisLine: {
   
              show: false, // 不显示x轴
              lineStyle: {
   
                color: &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值