Vue3使用ECharts的曲线条形堆叠混合图

先上效果图

 

图表容器

<div id="leftChart" style="height: 28vh"></div>
<div id="rightChart" style="height: 28vh"></div>

 

 监听resize视图窗口大小,可以让chart图表自适应大小

const leftChart = () => {
  const chartBox = echarts.init(document.getElementById('leftChart')) 
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      }
    },
    legend: {
      data: ['平均外温', '平均室温', '日供热量', '预测日供热量']
    },
    xAxis: [
      {
        type: 'category',
        data: ['1-1', '1-2', '1-3', '1-4', '1-5', '1-6', '1-7'],
        axisPointer: {
          type: 'shadow'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '供热量',
        min: 0,
        max: 1000.0,
        interval: 200.0,
        axisLabel: {
          formatter: '{value} GJ'
        }
      },
      {
        type: 'value',
        name: '温度',
        min: 5,
        max: 30,
        interval: 5,
        axisLabel: {
          formatter: '{value} °C'
        }
      }
    ],
    series: [
      {
        name: '平均外温',
        type: 'line',
        smooth: true,
        yAxisIndex: 1,
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' °C'
          }
        },
        data: [12.0, 12.2, 13.3, 14.5, 16.3, 10.2, 10.3]
      },
      {
        name: '平均室温',
        type: 'line',
        smooth: true,
        yAxisIndex: 1,
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' °C'
          }
        },
        data: [21.0, 21.2, 23.3, 24.5, 26.3, 20.2, 20.3]
      },
      {
        name: '日供热量',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' GJ'
          }
        },
        data: [200.0, 400.9, 700.0, 230.2, 250.6, 760.7, 135.6]
      },
      {
        name: '预测日供热量',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' GJ'
          }
        },
        data: [200.6, 500.9, 900.0, 260.4, 280.7, 700.7, 175.6]
      }
    ]
  }
  option && chartBox.setOption(option)
  window.addEventListener('resize', function () {
    chartBox.resize()
  })
}
const rightChart = () => {
  const chartBox = echarts.init(document.getElementById('rightChart'))
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      }
    },
    legend: {
      data: ['平均外温', '日供热量', '预测日供热量']
    },
    xAxis: [
      {
        type: 'category',
        data: ['1-1', '1-2', '1-3', '1-4', '1-5', '1-6', '1-7'],
        axisPointer: {
          type: 'shadow'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '排放量',
        min: 0,
        max: 1000.0,
        interval: 200.0,
        axisLabel: {
          formatter: '{value} t'
        }
      },
      {
        type: 'value',
        name: '温度',
        min: 5,
        max: 30,
        interval: 5,
        axisLabel: {
          formatter: '{value} °C'
        }
      }
    ],
    series: [
      {
        name: '平均外温',
        type: 'line',
        smooth: true,
        yAxisIndex: 1,
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' °C'
          }
        },
        data: [12.0, 12.2, 13.3, 14.5, 16.3, 10.2, 10.3]
      },

      {
        name: '日供热量',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' GJ'
          }
        },
        data: [200.0, 400.9, 700.0, 230.2, 250.6, 760.7, 135.6]
      },
      {
        name: '预测日供热量',
        type: 'bar',
        tooltip: {
          valueFormatter: function (value: any) {
            return value + ' GJ'
          }
        },
        data: [200.6, 500.9, 900.0, 260.4, 280.7, 700.7, 175.6]
      }
    ]
  }
  option && chartBox.setOption(option)
  window.addEventListener('resize', function () {
    chartBox.resize()
  })
}

 leftChart()
 rightChart()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值