来自数据库的动态图表

时间:2019-05-26 16:37:24

标签: javascript google-chartwrapper

我想从数据库中创建一个动态图。该图仅考虑了数据库的最后一个值,因此我的图仅包含一个值,而不是整个数据库。

我使用javascript和Google Charts API

function donutdraw() {
    $.ajax({
    url : 'bdd.php', // requesting a PHP script
    dataType : 'json',
      success : function (data) { // data contains the PHP script output
      var partie = data.partie;
      var partiecount = data.partiecount;


        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
        ]);
        data.addRows(2);

        for (var i = partie.length; i >= 0; i--) {
          for (var i = partiecount.length; i >= 0; i--) {
            var nb = 0;
            data.setCell(nb,0, partie);
            data.setCell(nb,1, parseInt(partiecount));
            nb = nb + 1;
          }
        }

        var options = {
          title: 'Répartition des attaques',
          pieHole: 0.4,
          width: 600,
          height: 400,
        };

        var chart = new google.visualization.PieChart(document.getElementById("donutchart"));
        chart.draw(data, options);
        },
    })

}
    //GRAPHE 5
    $grap5rep1 = $bdd->query('SELECT Cible AS partie FROM Mail GROUP BY Cible');
    $grap5rep2 = $bdd->query('SELECT COUNT(Cible) AS partiecount FROM Mail GROUP BY Cible');


    while ($donnees = $grap5rep1->fetch()){
     $partie=$donnees['partie'];
    }
    $grap5rep1->closeCursor();

    while ($donnees = $grap5rep2->fetch()){
     $partiecount=$donnees['partiecount'];
    }
    $grap5rep2->closeCursor();

0 个答案:

没有答案