【转】vue 引入 g2plot


原文地址:https://www.itshutong.com/articles/499/vue-introduces-g2-plot

首先安装扩展

$ npm install @antv/g2plot

接下来并不需要在 main.js 入口文件去引入,直接在需要使用 g2plot 的 vue 文件中引用相应的组件即可。如:

<template>
    <div id="c1"></div>
</template>
<script>
import { Bar } from '@antv/g2plot'
export default {
    // ...
    mounted () {
    const data = [
      { year: '1951 年', sales: 38 },
      { year: '1952 年', sales: 52 },
      { year: '1956 年', sales: 61 },
      { year: '1957 年', sales: 145 },
      { year: '1958 年', sales: 48 }
    ]

    const barPlot = new Bar('c1', {
      data,
      xField: 'sales',
      yField: 'year',
      colorField: 'year'
    })

    barPlot.render()
  }
}
</script>

效果如下:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM