
let dataMap={
    0:[0, 0, 0, 0, 0, 0, 40],
    1:[0, 0, 0, 0, 0, 0, 90]
}

function update(line,tag,val)
{
    obj=line.datasets[tag].points
    dataMap[tag].pop()
    dataMap[tag].unshift(val)
    for (const key in dataMap[tag]) 
    {
        obj[key].value=dataMap[tag][key]
    }
    line.update();
}



!async function ()
{
    await $M.include("http://s.nodejs.cn/chart/assets/Chart.min.js")
    var data = {
        labels: ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7"],
        datasets: [
            {
                label: "data0",
                fillColor: "rgba(220,220,220,0.7)",
                strokeColor: "rgba(220,220,220,1)",
                pointColor: "rgba(220,220,220,1)",
                pointStrokeColor: "#fff",
                pointHighlightFill: "#fff",
                pointHighlightStroke: "rgba(220,220,220,1)",
                data: dataMap[0]
            },
            {
                label: "data1",
                fillColor: "rgba(151,187,205,0.4)",
                strokeColor: "rgba(151,187,205,1)",
                pointColor: "rgba(151,187,205,1)",
                pointStrokeColor: "#fff",
                pointHighlightFill: "#fff",
                pointHighlightStroke: "rgba(151,187,205,1)",
                data: dataMap[1]
            }
        ]
    };

    var ctx = $M.find("#myChart").getContext("2d");
    var line=new Chart(ctx).Line(data, {
        bezierCurve: true
    });

    // $M.find('#myChart').rely
    // (
    //     'html','interval',(data)=>
    //     {
    //         update(line,0,Math.random()*100)
    //         update(line,1,Math.random()*100)  
    //     }
    // )

    $M.setInterval
    (
        '#myChart',()=>
        {
            update(line,0,Math.random()*100)
            update(line,1,Math.random()*100)  
        },
        1000
    )
}()