首页 前端知识 echarts实现上下拼接两个折线图,Y轴在一侧,不同比例的高,且合并tooltip

echarts实现上下拼接两个折线图,Y轴在一侧,不同比例的高,且合并tooltip

2024-06-19 08:06:49 前端知识 前端哥 22 321 我要收藏
  • 实现效果
    在这里插入图片描述

  • 说明

    •     grid:[
          //0降雨
          {x: '8%', y: '7%',height: '25%'},
          //流量
          {x: '8%', y2: '7%', height: '52%',bottom: '70px',}
          ],
      
  • 完整代码

    init() {
      let option = {
        //提示框
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        grid:[
          //0降雨
          {x: '8%', y: '7%',height: '21%'},
          //流量
          {x: '8%', y2: '7%', height: '48%',bottom: '70px',}
        ],
        toolbox: {
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: false },
            restore: { show: true },
            saveAsImage: { show: true },
          },
          iconStyle: {
            borderColor: "#c7d8f8",
          },
        },
        //图标上方提示
        legend: {
          data: [
            { name: '流量', textStyle: { color: '#00fa9a' } },
            { name: '雨量', textStyle: { color: '#6495ed' } },
          ],
          orient: "horizontal",
          x: "center",
          y: "top",
          backgroundColor: "none",
          borderColor: "#ccc",
          borderWidth: 0, 
          padding: 5, 
          itemGap: 10, 
          itemWidth: 20, 
          itemHeight: 14, 
          textStyle: {
            color: "#c7d8f8", 
          },
        },
        calculable: true,
        axisPointer: {
          link: { xAxisIndex: 'all' },
        },//合并tooltip
        xAxis: [
          {
            show:false,
            type: "category",
            gridIndex: 0, // 与grid数组对应
            data: this.$store.state.map.EchartsData1,
            axisLine:{
              show:true,
              lineStyle:{color:'#c7d8f8'},
              onZero: false
            },
          },
          {
            type: "category",
            gridIndex: 1,// 与grid数组对应
            data: this.$store.state.map.EchartsData1,
            axisLine:{
              show:true,
              lineStyle:{color:'#c7d8f8'},
              onZero: false
            },
          },
        ],
        yAxis: [
          {
            name: "流量(m³/s)",
            type: "value",
            gridIndex:1, // 与grid数组对应
            nameLocation:'middle',
            nameGap: 40,
            axisLine:{
              show:true,
              lineStyle:{color:'#c7d8f8'},
            },
          },
          {
            name: "雨量(mm)",
            nameLocation:'middle',
            nameGap: 40,
            type: "value",
            axisLine:{
              show:true,
              lineStyle:{color:'#c7d8f8'},
            },
            inverse: true,
          },
        ],
        series: [
          {
            name: "流量",
            type: "line",
            smooth: true,
            xAxisIndex:1, // 与X轴数组对应
            yAxisIndex: 0,
            data: this.$store.state.map.EchartsData2,
            itemStyle: {
              normal: {
                color: "#00fa9a",
              },
            },
          },
          {
            name: "雨量",
            type: "bar",
            barCategoryGap:'0%',
            smooth: true,
            yAxisIndex: 1,
            xAxisIndex:0,
            data: this.$store.state.map.EchartsData3,
            itemStyle: {
              normal: {
                color: "#6495ed",
              },
            },
          },
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
            xAxisIndex: [0,1],
          },
          {
            start: 0,
            end: 100,
          },
        ],
      };

      let myChart = echarts.init(document.querySelector(".charts"));
      myChart.setOption(option, true);
    },
转载请注明出处或者链接地址:https://www.qianduange.cn//article/12787.html
标签
评论
发布的文章

期末总结

2024-06-29 19:06:42

爱心

2024-06-27 17:06:24

表白代码

2024-06-27 16:06:42

html5 css3 前端基础认识。

2024-06-26 23:06:18

CFT Show 信息收集篇

2024-06-26 23:06:28

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!