vue + echarts

echarts官网配置项手册vue-echarts github链接

1.安装

npm i v-charts echarts -save

2. 按需导入需要使用的组件

import VChart from 'vue-echarts'
import { use } from 'echarts/core'
import { CanvasRenderer, SVGRenderer } from 'echarts/renderers'
import { BarChart, LineChart } from 'echarts/charts'

import {
  TitleComponent,
  LegendComponent,
  LegendScrollComponent,
  GridComponent,
  DatasetComponent,
  TooltipComponent,
} from 'echarts/components'

use([
  SVGRenderer,
  CanvasRenderer,
  BarChart,
  LineChart,
  GridComponent,
  TitleComponent,
  DatasetComponent,
  TooltipComponent,
])

3. 在man.js中注册全局组件

import { createApp } from 'vue'
const app = createApp(App)
app.component('VChart', VChart)

4. 使用,需要给其容器设置固定宽高

<template>
  <div class="w-96 h-96">
    <v-charts :option="chartData" autoresize></v-charts>
  </div>
</template>
<script lang="ts" setup>
import { reactive } from 'vue'
const chartData = reactive({
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'line',
        lineStyle: {
          type: 'solid',
        },
      },
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true,
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        splitLine: {
          lineStyle: {
            type: 'solid',
          },
        },
        data: ,
      },
    ],
    yAxis: [
      {
        type: 'value',
        splitLine: {
          lineStyle: {
            type: 'dashed',
          },
        },
      },
    ],
    series: [
      {
        name: 'Email',
        type: 'line',
        stack: 'Total',
        showSymbol: false,
        areaStyle: {
          opacity: 0.2,
        },
        lineStyle: {
          width: 1,
        },
        data: [
          520, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210,
          120, 132, 101, 134, 90, 230, 210, 120, 132, 200,
        ],
      },
      {
        name: 'Union Ads',
        type: 'line',
        stack: 'Total',
        showSymbol: false,
        areaStyle: {
          opacity: 0.2,
        },
        lineStyle: {
          width: 1,
        },
        data: [
          220, 182, 191, 234, 290, 330, 310, 220, 182, 191, 234, 290, 330, 310,
          220, 182, 191, 234, 290, 330, 310, 220, 182, 191,
        ],
      },
      {
        name: 'Video Ads',
        type: 'line',
        stack: 'Total',
        showSymbol: false,
        areaStyle: {
          opacity: 0.2,
        },
        lineStyle: {
          width: 1,
        },
        data: [
          150, 232, 201, 154, 190, 330, 410, 150, 232, 201, 154, 190, 330, 410,
          150, 232, 201, 154, 190, 330, 410, 150, 232, 201,
        ],
      },
      {
        name: 'Direct',
        type: 'line',
        stack: 'Total',
        showSymbol: false,
        areaStyle: {
          opacity: 0.2,
        },
        lineStyle: {
          width: 1,
        },
        data: [
          320, 332, 301, 334, 390, 330, 320, 320, 332, 301, 334, 390, 330, 320,
          320, 332, 301, 334, 390, 330, 320, 320, 332, 301,
        ],
      },
    ],
  })
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值