javascript - Create a dynamic Bar graph using Chart.js where data is from database -


i have been working on issue week , more until not able achieve right output this.

i working online system data project database. have table enrollment records in database. using chart.js, wanted show dynamic bar graph of yearly enrollment. bar graph works shows inaccurate result count not match right year.

i noticed, happens because when year no data, other year fills year, making result wrong.

what ignore empty year data or set zero. hope can understand problem, because have been searching solutions can't find right answer.

<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.6.0/chart.min.js"></script> 
<script>     var year = ['2000','2001','2002', '2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020'];     var female = <?php echo $female; ?>;     var male = <?php echo $male; ?>;      var entrancedataset = {                   label: 'female',                   type: 'bar',                   yaxesid : "y-axis-1",                   data: female,                   backgroundcolor: 'rgba(0, 204, 0, 0.2)',                   bordercolor: 'rgba(0, 204, 0,1)',                   borderwidth: 1               };          var dataset = [];         dataset.push(entrancedataset);            var exitdataset = {                     label: 'male',                     type: 'bar',                     yaxesid : "y-axis-1",                     data: male,                     backgroundcolor: 'rgba(54, 162, 235, 0.2)',                     bordercolor: 'rgba(54, 162, 235, 1)',                     borderwidth: 1                 };            dataset.push(exitdataset);          var ctx = $('#enrollcanvas');          mainthroughputchart = new chart(ctx, {             type: 'bar',             data: {                 labels: year,                 datasets: dataset             },             options: {                 scales: {                     xaxes : [{                       gridlines : {                             display : false                         },                         scalelabel: {                             display: true,                             labelstring: 'year'                           }                     }]                 },              }         });   </script> 

enter image description here

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -