Echarts 条形图

Echarts 条形图

在这里插入图片描述

var source = [
  ['score', 'amount', 'product'],
  [89.3, 58212, 'Matcha Latte'],
  [57.1, 78254, 'Milk Tea'],
  [74.4, 41032, 'Cheese Cocoa'],
  [50.1, 12755, 'Cheese Brownie'],
  [89.7, 20145, 'Matcha Cocoa'],
  [68.1, 79146, 'Tea'],
  [19.6, 91852, 'Orange Juice'],
  [10.6, 101852, 'Lemon Juice'],
  [32.7, 20112, 'Walnut Brownie'],
].sort((a, b) => {
  return a[1] - b[1];
});

var option = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow',
    },
    textStyle: {
      color: '#3c3c3c',
    },
    backgroundColor: 'rgba(255, 255, 255, 0.8)',
    extraCssText: 'box-shadow: 10px 10px 10px 0 rgba(0,0,0,0.20); padding: 10px 14px;border-radius: 4px;',
  },
  dataset: {
    source: source,
  },
  grid: {
    containLabel: true,
    left: '1%',
    right: '8%',
    bottom: '2%',
    top: '2%',
  },
  xAxis: {
    name: '',
    show: false,
  },
  yAxis: {
    type: 'category',
    axisLabel: {
      interval: 0,
      color: '#5c5c5c',
    },
    axisLine: {
      show: false,
    },
    axisTick: {
      inside: true,
      show: false,
    },
  },
  visualMap: {
    orient: 'horizontal',
    left: 'center',
    min: 12755,
    max: 101852,
    text: ['高分', '低分'],
    dimension: 1,
    inRange: {
      color: ['#D7DA8B', '#E15457'],
    },
  },
  series: [
    {
      type: 'bar',
      label: {
        show: true,
        position: 'right',
        formatter(val) {
          return '    $' + val.data[1];
        },
        /* rich: {
          text: {
            align: 'left',
            height: 20,
            fontSize: 14,
            verticalAlign: 'middle',
          },
        }, */
      },
      encode: {
        // Map the "amount" column to X axis.
        x: 'amount',
        // Map the "product" column to Y axis
        y: 'product',
      },
      itemStyle: {
        barBorderRadius: 50,
        color: function({ dataIndex }) {
          const colorList = [
            '#3C7EF2',
            '#3E82F3',
            '#4288F4',
            '#448CF4',
            '#4791F4',
            '#4791F4',
            '#4D9CF6',
            '#50A0F6',
            '#53A6F7',
            '#56ABF8',
            '#5AB0F9',
            '#5CB5F9',
            '#60BBFA',
            '#62BFFB',
            '#65C4FB',
            '#67C8FB',
            '#6BCEFC',
            '#6ED3FD',
            '#71D9FD',
            '#75E0FE',
          ];
          return colorList.reverse()[dataIndex > colorList.length - 1 ? colorList.length - 1 : dataIndex];
        },
      },
      barWidth: 10,
    },
  ],
};
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值