
let dataMap={
    0:[0, 0, 0, 0, 0, 0, 0,0,0,0],
    1:[0, 0, 0, 0, 0, 0, 0,0,0,0],
    2:[0, 0, 0, 0, 0, 0, 0,0,0,0]
}

function update(line,tag)
{
    let obj=line.datasets[tag].points
    for (let key in dataMap[tag]) 
    {
        obj[key].value=dataMap[tag][key]
    }
    
}

function updateAll(line,tagList)
{
    for (let index = 0; index < tagList.length; index++) 
    {
        let cur=tagList[index]
        update(line,cur)
    }
    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", "tag8", "tag9", "tag10"],
        datasets: [
            {
                label: "data0",
                fillColor: "rgba(90,150,100,0.5)",
                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]
            },
            {
                label: "data2",
                fillColor: "rgba(200,0,50,0.2)",
                strokeColor: "rgba(250,150,200,1)",
                pointColor: "rgba(255,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,
    });


    function gen(tag,arr)
    {
        let count=dataMap[tag].length
        for (let index = 0; index < count; index++) 
        {
            dataMap[tag][index]+=arr[index]
        }
    }

    
    $M.find('#myChart').rely
    (
        'html','content-com-statis-update',(event)=>
        {
            let obj=event.detail
            gen(0,obj.sho)
            gen(1,obj.rand)
            gen(2,obj.seed)
            updateAll(line,[0,1,2])
            $M.dispatch('html','content-com-code-update',obj)
        }
    )
}()
