duanchifo2866
duanchifo2866
采纳率100%
2019-05-27 14:36

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

I am trying to pass values ​​to my graph in chartjs, this data comes from Mysql and Php, I attach the code:

Then I used Ajax to be able to reuse the code I send in Json format but I need that each line of my graphic is a respective "interface" and the data that I will show is "max_usage" and "week" that come from within the same array that has name the interface

Code 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],
                            }]
                        },```
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答