vue3 引入echarts(未使用Ts)

官网引入echarts

快速上手 - Handbook - Apache ECharts

npm install echarts --save

在项目需要使用的页面进行引入

import * as echarts from 'echarts';
<div class="myEcharts" ref="mainEcharts"></div>
import {ref,onMounted} from "vue";

const boxListFirst = ref({
  xAxis:['10-20','10-21','10-22','10-23','10-24','10-25','10-26','10-27','10-28','10-29','10-30','10-31','11-01','11-02','11-03','11-04','11-05','11-06','11-07','11-08'],
  yAxis:['1000','2000','1500','1600','2500','3000','1000','2000','1500','1600','2500','3000','1000','2000','1500','1600','2500','1000','2000','3000']
})
const mainEcharts = ref()

function initEcharts() {
  // 基于准备好的dom,初始化echarts实例
  let myChart = echarts.init(mainEcharts.value);
  // 指定图表的配置项和数据
  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'line',
        label: {
          backgroundColor: '#BBC9DB'
        }
      }
    },
    grid:{ // 让图表占满容器
      top:"30px",
      left:"80px",
      right:"40px",
      bottom:"20px"
    },
    // x轴设置
    xAxis: {
      data: boxListFirst.value.xAxis,
      axisTick: {
        show: true
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#6388b9' // 设置 x 轴线条颜色
        }
      },
      axisLabel: {
        color: '#BBC9DB',
        fontSize: 12
      }
    },
    dataZoom: [
      {
        type: 'inside', // 设置为滑动条类型
        start: 0, // 起始位置为0
        end: 100 // 结束位置为第7个数据点,因为索引从0开始,所以是6
      }
    ],
    // y轴设置
    yAxis: [
      {
        // 第一条纵坐标轴
        type: 'value',
        name:'单位/单',
        nameTextStyle: {
          color: "#D1E4FF",
          fontSize: 14,
          padding: [0, 0, 0, 0], //name文字位置 对应 上右下左
        },
        position: 'left',
        axisLine: {
          show: true,
          lineStyle: {
            color: '#6388b9' // 设置 y 轴线条颜色
          }
        },

        splitLine: {
          //网格线
          show: true, //是否显示
          lineStyle: {
            //网格线样式
            color: 'rgba(27,69,126)', //网格线颜色
            width: 1, //网格线的加粗程度
            type: 'dashed' //网格线类型
          }
        },
        axisLabel: {
          color: '#BBC9DB',
          fontSize: 14,
          // interval: 0,
          // rotate: 35
          formatter: '{value}'
        }
      }
    ],
    // 数据系列
    series: [
      {
        name: '当月订单量(条)',
        type: 'bar',
        data: boxListFirst.value.yAxis, // 系列2对应的数据
        yAxisIndex: 0,
        barWidth: 25,
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: 'rgb(27,174,243, 1)' },
            { offset: 1, color: 'rgb(57,141,255, 1)' }
          ])
        }
      }
    ]
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
onMounted(
    () => {
      initEcharts()
    }
)

 

grid:{ // 让图表占满容器
  top:"30px",
  left:"80px",
  right:"40px",
  bottom:"20px"
},

grid 确定是否铺满区域

nameTextStyle: {
  color: "#D1E4FF",
  fontSize: 14,
  padding: [0, 0, 0, 0], //name文字位置 对应 上右下左
},

nameTextStyle Y轴上方name样式调整

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值