Chartjs-Pie chart with Chart.js and mySQL

3👍

In case you’re still trying to get it to work, here is how I did it:

<script type="text/javascript">

$.ajax({
url:"getdata.php",
method:"GET",
success:function(data)  {
console.log(data);
var malenum =[1];
var femalenum =[2];



var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
  type: 'pie',
  data: {
      labels: ["Male","Female"],
    datasets: [{
        label: 'Genders',
        data: [malenum,femalenum],
        backgroundColor: [
            'rgba(255, 99, 132, 0.2)',
            'rgba(54, 162, 235, 0.2)'
        ],
        borderColor: [
            'rgba(255,99,132,1)',
            'rgba(54, 162, 235, 1)'
        ],
        borderWidth: 1
    }]
},

});

},
error:function(data){
    console.log(data);
}
});
</script>

Leave a comment