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

如何从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],
                            }]
                        },```
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?