antvg2 环图轮播_在vue项目中引用Antv G2,以饼图为例讲解

我就废话不多说了,大家还是直接看代码吧~

npm install @antv/g2 --save

template内容:

js部分:

​//引入G2组件

import G2 from "@antv/g2";

export default {

name:"",

//数据部分

data(){

return{

sourceData: [],//声明一个数组

chart: {}, //全局定义chart对象

id: Math.random().toString(36).substr(2), //动态生成ID,便于多次引用

}

},

//初始加载

mounted() {

this.initComponent();

},

methods: {

//初始化获取数据

initStrateGoal() {

debugger;

let _this = this;

_this.$http

.$get("后台接口地址")

.then(function(response) {

if (_this.$util.isBlank(response.data)) {

return;

}

_this.sourceData = response.data;

//调用绘图方法

_this.getDrawing(_this.sourceData);

})

.catch(function(error) {

_this.$message.error(_this, error);

});

},

//绘制图形

getDrawing(sourceData) {

let _this = this;

// Step 1: 创建 Chart 对象

_this.chart = new G2.Chart({

container: _this.id,

forceFit: true,

height: 255,

padding: [30, 0, 35, 0],

animate: false

// margin: [0, 500]

});

let sumCount = 0;

for (let i in sourceData) {

sumCount = sumCount + Number(sourceData[i].count);

}

// Step 2:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值