敲~代~码~!!!🍺|

于影而驰

园龄:2年6个月粉丝:0关注:0

2022-09-22 23:24阅读: 109评论: 0推荐: 0

vue引入echarts

首先是npm下载

1
npm install echarts --save

  

 

配置echarts.js,按需引入

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
// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core';
// 引入柱状图图表,图表后缀都为 Chart
import { BarChart } from 'echarts/charts';
// 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent
} from 'echarts/components';
// 标签自动布局,全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features';
// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers';
 
// 注册必须的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  BarChart,
  LabelLayout,
  UniversalTransition,
  CanvasRenderer
]);
 
export default echarts

  

 

  vue页面使用

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
  <div class="box boxall">
    <h2>就业行业</h2>
    <div class="contain blt">
      <div id="main"></div>
    </div>
    <div class="boxfoot"></div>
  </div>
</template>
<script>
import echarts from "@/utils/echarts";
export default {
  mounted() {
    this.initCharts(); //初始化渲染echart图标
  },
 
  methods: {
    initCharts() {
      //  获取数据
      const option = {
        grid: {
          top: "15%",
          left: "10%",
          right: "8%",
          bottom: "10%",
        },
        color: ["#2f89cf"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        xAxis: {
          data: [ "旅游行业","教育培训", "游戏行业", "医疗行业", "电商行业", "社交行业", "金融行业" ],
          axisLabel: {
            color: "rgba(255,255,255,.8)",
            fontSize: 12,
            fontWeight: "bold",
          },
          axisLine: {
            show: false,
          },
        },
        yAxis: {
          axisLabel: {
            color: "rgba(255,255,255,.8)",
            fontSize: 12,
            fontWeight: "bold",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "rgba(255,255,255,.3)",
              width: 2,
            },
          },
        },
        series: [
          {
            name: "比率",
            type: "bar",
            barWidth: "50%",
            itemStyle: {
              borderRadius: 5,
            },
            data: [200, 300, 300, 900, 1500, 1200, 600]
          },
        ],
      };
      var myChart = echarts.init(document.getElementById("main")); //图标初始化
      myChart.setOption(option); // 渲染页面
      // 随着屏幕大小调节图标
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
  },
};
</script>
<style lang='less' scoped>
#main {
  width: 100%;
  height: 100%;
}
</style>

  

 

本文作者:于影而驰

本文链接:https://www.cnblogs.com/Action-shadow/p/16721218.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   于影而驰  阅读(109)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起