


let redList=[1,3,5,7,9,2,32,11,3,45,6,4,9,11,42,3,4,2,4]



let temp='rgba(red, gren, blue, 0.7)'

let tempList= [
    'rgba(255, 99, 132, 0.7)',
    'rgba(54, 162, 235, 0.7)',
    'rgba(255, 206, 86, 0.7)',
    'rgba(75, 192, 192, 0.7)',
    'rgba(153, 102, 255, 0.7)',
    'rgba(255, 159, 64, 0.7)'
]
let tempbList=[]


await $M.include("/public/default/js/Chart.js")
var ctx = $M.find("#myChart").getContext("2d")

function 绘制(redList)
{
    redList=redList?redList:[]
    redList=redList.sort
    (
        (a,b)=>
        {
            return b-a
        }
    )
    if(redList.length>7)
    {
        for (let index = 7; index < redList.length; index++) 
        {
            let rand=Math.random()
            let red=rand*250
            let gren=rand*100
            let blue=rand*250
            let tempCur=temp.replace('red',red)
            .replace('gren',gren)
            .replace('blue',blue)
        
            tempList.push(tempCur)
        }
    }
    new Chart(ctx, {
        type: 'doughnut',
        data: {
            labels: redList,
            datasets: [{
                label: '# of Votes',
                data: redList,
                backgroundColor: tempList,
                borderColor: tempbList,
                borderWidth: 1
            }]
        }
    });
}


$M.find('#myChart').rely
(
    'html','content-com-statis_bar-update',(event)=>
    {
        console.log(event.detail)
        绘制(event.detail.数组)
    }
)


