简体   繁体   English

Morris.js文件数据

[英]Morris.js file data

I am using mysql for data and then i get them with php... 我正在使用mysql作为数据,然后用php获取它们...

$array = data()->query("SELECT DATE(rezervacijaOpravljena) d, COUNT(id) visits FROM rezervacija GROUP BY d")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($array,JSON_NUMERIC_CHECK);    

Than in javascript (morris.js data) i am using following script: 比起javascript(morris.js数据),我正在使用以下脚本:

Morris.Line({         
    element: 'morris-line-chart',
    data:  $.ajax({             
            url: "dodajRezervacijo.php",
            success: function(html) {
            console.log(JSON.parse(html)[0]);   

            return JSON.parse(html)[0];         
            }
            })
        ,       
    // The name of the data record attribute that contains x-visitss.
    xkey: 'd',
    // A list of names of data record attributes that contain y-visitss.
    ykeys: ['visits'],
    // Labels for the ykeys -- will be displayed when you hover over the
    // chart.
    labels: ['Visits'],
    // Disables line smoothing
    smooth: true,
    resize: true
});    

But it is not working. 但这是行不通的。 I am a beginner in using ajax. 我是使用ajax的初学者。 Also is such use of php quering data good? 也是这样使用php查询数据好吗? or is better to have all things like(prepare and execute function separetly?)? 还是拥有所有类似的东西(分别准备和执行功能?)?

Get the data from your ajax call and in the success function call the morris graph. 从ajax调用中获取数据,并在成功函数中调用morris图。

That should do the trick. 这应该够了吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM