vue.js怎么引入echars


本文摘自PHP中文网,作者coldplay.xixi,侵删。

vue.js引入echars的方法:1、全局引入,代码为【title:{text: 'ECharts 入门示例'}】;2、按需引入,代码为【require('echarts/lib/component/tooltip')】。

【相关文章推荐:vue.js】

vue.js引入echars的方法:

1.安装echarts依赖

1

npm install echarts -S

2.创建图表

a:全局引入

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

main.js页面

import echarts from 'echarts'

Vue.prototype.$echarts = echarts

Hello.vue页面

<div id="myChart" :style="{width: '300px', height: '300px'}"></div>

<script>

export default {

  name: 'FuncFormsBase',

  data () {

    return {

      msg: 'Welcome to Your Vue.js App'

    }

  },

  mounted () {

    this.drawLine();

  },

  methods: {

    drawLine () {

      var echarts = require('echarts');

      var myChart = echarts.init(document.getElementById('main'));

      myChart.setOption({

        title: {

          text: 'ECharts 入门示例'

        },

        tooltip: {},

        xAxis: {

          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']

        },

        yAxis: {},

        series: [{

          name: '销量',

          type: 'bar',

          data: [5, 20, 36, 10, 10, 20]

        }]

      });

    }

  }

}

</script>

<style scoped>

</style>

b:按需引入

上面全局引入会将所有的echarts图表打包,导致体积过大,所以我觉得最好还是按需引入。

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

// 引入基本模板

let echarts = require('echarts/lib/echarts')

// 引入柱状图组件

require('echarts/lib/chart/bar')

// 引入提示框和title组件

require('echarts/lib/component/tooltip')

require('echarts/lib/component/title')

export default {

  name: 'hello',

  data() {

    return {

      msg: 'Welcome to Your Vue.js App'

    }

  },

  mounted() {

    this.drawLine();

  },

  methods: {

    drawLine() {

      // 基于准备好的dom,初始化echarts实例

      let myChart = echarts.init(document.getElementById('myChart'))

      // 绘制图表

      myChart.setOption({

        title: { text: 'ECharts 入门示例' },

        tooltip: {},

        xAxis: {

          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]

        },

        yAxis: {},

        series: [{

          name: '销量',

          type: 'bar',

          data: [5, 20, 36, 10, 10, 20]

        }]

      });

    }

  }

}

相关免费学习推荐:JavaScript(视频)

以上就是vue.js怎么引入echars的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

vue.js怎么请求数据

vue.js事件处理教程及代码示例

怎样启动一个vue.js项目

vue.js中的el什么意思

vue.js如何设置时间格式

vue.js怎样刷新改变数据

怎么检查vue.js是否安装成功了

vue.js怎么引入echars

vue.js中的功能组件的理解

vue.js怎么获取某个dom元素的值

更多相关阅读请进入《vue.js》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...