收藏
回答

echarts在小程序中如何 tab切换

 

wxml

<view class="se-time {{ currentLineNum == index ? 'active' :'' }}" wx:for="{{toggleTime1}}" bindtap="selectLTime" data-index="{{ index }}" wx:key="{{item}}">{{ item }}</view>


<view>

<ec-canvas class="line" id="line1" ec="{{ ec }}"></ec-canvas>

</view>

js

let that;

let aid;

let app = getApp();

function initChart(canvas, width, height) {

    const Chart = echarts.init(canvas, null, {

        width: width,

        height: height

    });

    canvas.setChart(Chart);

    api.reGet(api.grossValue, {

        companyid: aid,

        type: that.data.type,

        assetType: "S"

    })

    .then((res) => {

        let re = res.data.data;

        let data = [];

        let leg = [];

        re.forEach(function (item) {

            data.push(item.score);

            leg.push(item.dd);

        })

        Chart.setOption(chart.noTitleLine(leg, data))

            return chart;

        })

}


page{

    data: {

    currentLineNum: 2,

     toggleTime1: ["年", "月", "日"],

        type:"D",

        line1:{

            onInit: initChart

        }

    },

    onLoad() {

        that = this;

    },

selectLTime(e) {

    let index = e.currentTarget.dataset.index;

    this.setData({

        currentLineNum: index

    })

    if (index == 0) {

        this.data.type = 'Y'

    }

    else if (index == 1) {

        this.data.type = 'S'

    }

    else {

        this.data.type = 'D'

    }

initChart() //如果这么写 就会报错, 大家这种情况会怎么写

   },

}

最后一次编辑于  2018-10-24  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏

1 个回答

  • 小居
    小居
    2018-10-24

     const Chart = null;
    function initChart(canvas, width, height) {

        Chart  = echarts.init(canvas, null, {

            width: width,

            height: height

        });


    }
    切换
    selectLTime(){
        Chart.setOption(...)
    }


    2018-10-24
    赞同 1
    回复 1
    • 小泽摔不倒
      小泽摔不倒
      2018-10-24

      谢谢 大哥

      2018-10-24
      回复