Echarts 显示双Y轴

option 对象 

option = {
  yAxis: [
    { name: '重量(kg)', position: 'left', type: 'value' },
    { name: '金额(元)', position: 'right', type: 'value' }
  ],
  xAxis: { type: 'category' },
  legend: {},
  series: [
    {
      name: '剩余量',
      label: { normal: { show: true, position: 'insideRight' } },
      type: 'bar',
      // 适用于第一个Y轴
      yAxisIndex: 0
    },
    {
      name: '浪费量',
      label: { normal: { show: true, position: 'insideRight' } },
      type: 'bar',
      yAxisIndex: 0
    },
    {
      name: '浪费额',
      label: { normal: { show: true, position: 'insideRight' } },
      type: 'line',
      yAxisIndex: 1
    }
  ],
  tooltip: {},
  title: { text: '每日剩余数据' },
  dataset: {
    source: [
      { 剩余量: '0.11', product: '2023-07-10', 浪费额: '0.21', 浪费量: '0.11' },
      { 剩余量: '0.10', product: '2023-07-11', 浪费额: '0.22', 浪费量: '0.10' },
      { 剩余量: '0.12', product: '2023-07-12', 浪费额: '0.21', 浪费量: '0.12' },
      { 剩余量: '0.09', product: '2023-07-13', 浪费额: '0.14', 浪费量: '0.09' },
      { 剩余量: '0.00', product: '2023-07-14', 浪费额: '0.00', 浪费量: '0.00' },
      { 剩余量: '0.00', product: '2023-07-15', 浪费额: '0.00', 浪费量: '0.00' },
      { 剩余量: '0.00', product: '2023-07-16', 浪费额: '0.00', 浪费量: '0.00' }
    ],
    dimensions: ['product', '剩余量', '浪费量', '浪费额']
  }
};

只需将option set即可

showCharts(option, elementId) {
      let myChart = echarts.init(document.getElementById(elementId));
      myChart.clear();
      myChart.setOption(option);
    },

生成的图

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值