如何从Php和Mysql给图表js的图赋值?

时间:2019-05-27 14:36:57

标签: javascript php mysql json ajax

我试图将值传递给chartjs中的图形,该数据来自Mysql和Php,我附上代码:

然后,我使用Ajax来重用以Json格式发送的代码,但是我需要图形的每一行都是各自的“接口”,而我将显示的数据是“ max_usage”和“ week”,来自同一个名称为接口的数组中

代码PHP:

    while($row = $result->fetch_assoc()){
        if(!isset($data[$row["INTERFACE"]])){
            $data[$row["INTERFACE"]] = array();
        }
        array_push($data[$row['INTERFACE']], $row);
    }
}```


Code ajax.

``` function (data) {

                    let interfase = [];
                    for (let i in data){
                        interfase.push(i);
                    }
                    console.log(interfase);

                    var ctx = document.getElementById('myChart').getContext('2d');
                    var chart = new Chart(ctx, {
                        // The type of chart we want to create
                        type: 'line',
                        data: {
                            labels: interfase,
                            datasets: [{
                                label: 'asdsa',
                                backgroundColor: 'transparent',
                                borderColor: 'rgb(255,237,58)',
                                steppedLine: true,
                                data: [12],
                            }]
                        },```

0 个答案:

没有答案