echarts双Y轴等分

本文介绍了如何在Echarts中设置双Y轴并实现等分,包括安装Echarts步骤、main.js的配置方法以及具体使用案例,详细教程见链接。

1.安装ecarts

npm i echarts -S

2.main.js配置

import Vue from 'vue'
import App from './App'
import router from './router'

// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

3.使用

<template>
<div>
  
  <div id="twoY" style="width: 800px;height:400px;"></div>
 
</div>
</template>
<script>

export default {
  data(){
    return{
     leftData:[4,74,3,4,1,2],
     rightData:[233,255,444,888,69],
    }
  },
  created(){
    
  },
  mounted(){
 this.drawPic()
  },
  methods:{
    drawPic(){
//计算最大值
  function calMax(arr) {
    let max = 0;
    arr.forEach((el) => {
      el.forEach((el1) => {
        if (!(el1 === undefined || el1 === '')) {
          if (max < el1) {
            max = el1;
          }
        }
      })
    })
    let maxint = Math.ceil(max / 9.5);//不让最高的值超过最上面的刻度
    let maxval = maxint * 10;//让显示的刻度是整数
    return maxval;
  }
 
//   //计算最小值
  function calMin(arr) {
    let min = 0;
    arr.forEach((el) => {
      el.forEach((el1) => {
        if (!(el1 === undefined || el1 === '')) {
          if (min > el1) {
            min = el1;
          }
        }
      })
    })
    let minint = Math.floor(min / 10);
    let minval = minint * 10;//让显示的刻度是整数
    return minval;
  }
 
  
    let  Max1 = calMax([this.leftData]), Max2 =calMax([this.rightData]);


       let  myChart = this.$echarts.init(document.getElementById("twoY"));

const option = {
    "color": [
        "#1890ff",
        "#1f9"
    ],
    "grid": {
        top: "25%",
          right: "10%",
          left: "5%",
          bottom: "10%",
    },
    "legend": {
        top: 5,
          left: 250,
          itemWidth: 10,
          itemHeight: 10,
          textStyle: {
              fontSize: 14,
              color: 'red',
              padding: [3, 8, 0, 2]
          },
          data:['增长率', '数值'],
    },
  
     xAxis: [
        {
          type: "category",
          data: [
            "桥北",
            "镜湖",
            "目澜",
            "山塘",
            "坛丘",
            "衡悦"
        
          ],
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          splitLine: {
            show: false,
          },
          axisLabel: {
            color: "red",
            interval: 0,
            textStyle: {
              fontSize: 10,
            },
            fontFamily: "LCDEF",
          },
        },
      ],
    yAxis: [{
      name: '单位:万元',
       nameLocation: "start",
      nameTextStyle: {color: '#999999'},
      type: "value",
      axisLine: {show: false},
      axisTick: {show: false},
      axisLabel: {verticalAlign: "bottom", color: "#999999"},
      min: 0,
      max: Max1,
      splitNumber: 5,
      interval: Max1  / 5
    }, {
      name: '单位:%',
       nameLocation: "start",
      type: 'value',
      nameTextStyle: {color: '#999999'},
      axisLine: {show: false},
      axisTick: {show: false},
      axisLabel: {verticalAlign: "bottom", color: "#999999"},
      min: 0,
      max: Max2,
      splitNumber: 5,
      interval: Max2  / 5
 
    }],
    

    "series": [{
            "type": "line",
            "name": "数值",
            "data": this.leftData,
        
        },
        {
            "type": "line",
            "name": "增长率",
            "yAxisIndex": 1,
            itemStyle: {
                color: '#20C578',
            },
            symbolSize: 10,
            symbol: 'circle',
            "data":this.rightData
        }
    ]
};

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
  },
};
</script>

<style scoped lang="scss">


</style>

https://blog.youkuaiyun.com/qq_40845885/article/details/82108525

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值