antvis / wx-f2

F2 的微信小程序

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello, how can I solve the problem of chart.pieLabel is not a function when the pie chart reports an error? 你好,请问饼图报错 chart.pieLabel is not a function 怎么解决呢?

coderyqy opened this issue · comments

commented

唉,我看了好多条Issues,好像都没有解决方案啊。
看文档说明,PieLabel 插件默认没有打包至 @antv/f2 模块包中。
按照文档操作引入:const F2 = require('@antv/f2/lib/index-all');
但是这样引入又说找不到,怎么解决呢?

要修改源码,将PieLabel注册进去,然后npm重新打包,这样项目才能使用。
image

commented

试试替换这个js文件 -> 代码

commented

我想问一下,替换那个文件的js代码呢

commented

@xiongchenxu 可以给我说一下是替换那个文件里的么。或者把文件发给我一份谢谢啦

@xiongchenxu 可以给我说一下是替换那个文件里的么。或者把文件发给我一份谢谢啦

自己编译,重新构建就好了。
1.关闭微信小程序,进入 node_modules/@antv/wx-f2/src/index.js 注入代码:
const PieLabel = require('@antv/f2/lib/plugin/pie-label');
F2.Chart.plugins.register(PieLabel);
2.node_modules@antv\wx-f2路径下,执行 npm install、npm run build,完成后删除node_modules@antv\wx-f2\node_modules
3.重新打开微信小程序,开启npm使用功能,构建npm包。
此时PieLabel已经被注册到F2中了,无需引入,直接使用。其实还可以等F2 4.x,新的F2组件更好,不过官方更新的慢了点,主要是ScrollBar在F2 3.x的小程序中引入有BUG,F2 4.x解决了,等待官方更新新版本后,直接用新的吧。