echarts双x轴案例

该博客主要展示了如何使用ECharts组件在 Vue.js 应用中创建一个线图,包括设置图表标题、配置x轴和y轴、定义颜色和数据。通过监听`type`属性变化,动态调整x轴标签格式。示例代码详细地演示了如何初始化ECharts实例,设置图表选项,并在数据更新时更新图表。
摘要由CSDN通过智能技术生成

在这里插入图片描述

<template>
  <basic-container>
    <div class="inSec1Box">
      <!-- <div class="inSec1T">{{linEcharts.title}}</div> -->
      <div class="inSec1Con3">
        <!-- <div class="totalCon">
          <div class="totalNum">
            715
            <span>万</span>
          </div>
          <div>总冻结金额</div>
        </div> -->

        <div class="echartsBox" ref="totalMoney"></div>
      </div>
    </div>
  </basic-container>
</template>

<script>
export default {
  name: "lineEcharts",
  props: ["echarts", "linEcharts", "type"],
  data() {
    return {
      type2: "",
    };
  },
  methods: {
    //总冻结金额
    totalEchart() {
      var totalEchart = this.echarts.init(this.$refs.totalMoney);
      let option = {
        title: {
          text: this.linEcharts.title,
        },
        color: ["#32bdde", "#4e7dd7", "#ec5c5c"],
        legend: {
          itemWidth: 20,
          itemHeight: 6,
          right: "15%",
          data: this.linEcharts.legendData,
        },
        tooltip: {
          trigger: "axis",
          formatter: "{b}月 : {c} 人",
        },
        grid: {
          left: "3%",
          right: "5%",
          top: "20%",
          bottom: "5%",
          containLabel: true,
        },
        // calculable: true,
        xAxis: [
          // {
          //   axisLabel: {
          //      formatter: this.type2 == 0 ? '{value}年':'{value}月'
          //   },
          //   data:this.linEcharts.linX
          // },
          {
            type: "category",
            axisTick: {
              alignWithLabel: true,
            },
            // axisLine: {
            //     onZero: false,
            //     lineStyle: {
            //         color: colors[1]
            //     }
            // },
            axisPointer: {
              label: {
                formatter: function (params) {
                  return (
                    "降水量  " +
                    params.value +
                    (params.seriesData.length
                      ? ":" + params.seriesData[0].data
                      : "")
                  );
                },
              },
            },
            data: [
              "一月",
              "二月",
              "三月",
              "四月",
              "五月",
              "六月",
              "七月",
              "八月",
              "九月",
              "十月",
              "十一月",
              "十二月",
            ],
          },
          {
              type: 'category',
              position: 'bottom',
              offset: 25,
              axisPointer: {
                  type: 'none'
              },
              axisTick:{
                  show: false
              },
              axisLine:{
                  show: false
              },
            data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'],
          },
        ],
        yAxis: {
          type: "value",
          axisLabel: {
            textStyle: {
              color: "#B7B7B7",
              fontSize: "12",
            },
            formatter: "{value}",
          },
          splitLine: {
            lineStyle: {
              color: "#F9F9F9",
            },
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#CACACA",
            },
          },
        },

        // series: this.linEcharts.linData
        series: [
          {
            name: "2015 降水量",
            type: "line",
            // xAxisIndex: 1,
            smooth: true,
            data: [
              2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0,
              2.3,
            ],
          },
          {
            name: "2016 降水量",

            type: "line",
            smooth: true,
            data: [
              3.9, 5.9, 11.1, 18.7, 48.3, 69.2, 231.6, 46.6, 55.4, 18.4, 10.3,
              0.7,
            ],
          },
        ],
      };

      totalEchart.setOption(option);
    },
  },
  mounted() {
    // this.totalEchart();
  },

  watch: {
    type: function (newVal, olaVal) {
      this.type2 = newVal;
      this.$forceUpdate();
      //  console.log("监听数据2342423",olaVal)
    },
    linEcharts: {
      handler(newVal) {
        this.$nextTick(() => {
          console.log(JSON.stringify(newVal), "newVal");
          setTimeout(() => {
            this.totalEchart();
          });
        });
      },
      deep: true,
      // immediate:true,
    },
  },
};
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小四是个处女座

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值