Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何动态创建或刷新图表 #4

Open
shizuka0958 opened this issue Dec 28, 2018 · 4 comments
Open

如何动态创建或刷新图表 #4

shizuka0958 opened this issue Dec 28, 2018 · 4 comments

Comments

@shizuka0958
Copy link

业务中有个需求

  1. 初始化时创建图表实例,但使用wx:if=false隐藏
  2. 异步获取图表数据,然后changeData刷新图表数据,但是发现chart实例为null
    请问需要异步的获取数据后,创建或者刷新图表这种需求,正确的应该如何做?
@ChunrunHan
Copy link

请问,现在解决了吗?

@ChunrunHan
Copy link

加个延时ok

@ChunrunHan
Copy link

setTimeout(function(){
  chart.changeData(dataList); // 加载新数据
},1000)

@TSjianjiao
Copy link

定时器不保险吧,写个返回函数的函数就行了

let chart = {}
page({
    data: {
        opts:{
            onInit: () => {}
        },
        showChart: false
    },
    onLoad(options) {
       // 请求完成后再生成初始化函数 加载图表
      // 必须用wx:if控制图表 不然页面一加载就执行初始化了
       const func =  this.initChart(数据)
        this.setData({
            opts: {
                onInit: func
            },
            showChart: true
        })
    },
    initChart(data) {
       /// 返回一个初始化函数
        return function (canvas, width, height, F2) {
            chart = new F2.Chart({
                el: canvas,
                width,
                height
            });
            chart.source(data);
            // ,......
            chart.render();
            return chart;
        }
       
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants