echarts在小程序中如何 tab切换
发布于 5 年前 作者 qiangliu 10132 次浏览 来自 问答

 

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() //如果这么写 就会报错, 大家这种情况会怎么写

   },

}

1 回复

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

    Chart  = echarts.init(canvas, null, {

        width: width,

        height: height

    });


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

回到顶部