antvis / my-f2

F2 的支付宝小程序版本
MIT License
146 stars 23 forks source link

Line ChangeData无效 #52

Open zhongpeng opened 4 years ago

zhongpeng commented 4 years ago

const wf = require('wefetch'); let chart = null; const realTimedDataUrl = "https://a.cifm.com/data/getData?code=kamt.rtmin"; const sszs = "https://a.cifm.com/data/getData?code=trends2"; Page({ data: { data: [], }, onInitChart(F2, config) { let data = than.data.data; chart = new F2.Chart(config); chart.source(data); chart.scale('value', { tickCount: 5 }); chart.render(); return chart; },

getRealTimedData(needUpdate) {
    let data = [], than = this;
    const realTimedData = () => wf.get(realTimedDataUrl), sszsData = () => wf.get(sszs);
    wf.all([realTimedData(), sszsData()])
        .then(res => {
            let s2n = res[0].data.data.s2n;
            let trends = res[1].data.data.trends;
            s2n.forEach((item) => {
                let value = item.split(",")[5];
                if (value && value !== "-") {
                    if (value > 0) {
                        value = Math.abs(value / 10000).toFixed(2);
                    } else { value = "-"   Math.abs(value / 10000).toFixed(2); }
                    let obj = {};
                    obj['time'] = item.split(",")[0].split(":")[0] === "9" ? item.split(",")[0] = "09:"   item.split(",")[0].split(":")[1] : item.split(",")[0];
                    obj['name'] = "A";
                    obj['money'] = value;
                    trends.forEach((trend) => {
                        if (trend.split(',')[0].split(" ")[1] == obj['time']) {
                            obj['name1'] = "B";
                            obj['index'] = trend.split(',')[2]
                            data.push(obj);
                        }
                    });
                }
            })
            than.setData({
                data: data
            })
            if (needUpdate) {
                // fun(data);
                chart.repaint();
                chart.guide().clear();
                chart.changeData(data);
            }
        })
},

onLoad() { let than = this; than.getRealTimedData(false); setInterval(function () { than.getRealTimedData(true); }, 30000) }, })