Chartjs-How to generate multi bar chart in Chart.js with php & sql

0👍

I guess the only way to do this is to create multiple datasets instead of one. This may not be the best answer but this is how i did it.

<script type="text/javascript">

            /*****first chart********/
            var ctx = document.getElementById('myChart2').getContext('2d');
                var myChart = new Chart(ctx, {
                    type:<?php echo $chartype; ?>,
                    data : {
                      labels: [<?php echo $datelist_2; ?>], <!--label name->
                      datasets: [
                          { 
                            label: [<?php echo $dredgelist_2;?>],
                            data: [<?php echo $volumedatalist; ?>],
                            backgroundColor: <?php echo $barcolor; ?>
                          },
                          { 
                            label: [<?php echo yourVariable;?>],
                            data: [<?php echo yourVariable; ?>],
                            backgroundColor: <?php echo yourColor; ?>
                          },
                          { 
                            label: [<?php echo yourVariable;?>],
                            data: [<?php echo yourVariable; ?>],
                            backgroundColor: <?php echo yourColor; ?>
                          },
                          { 
                            label: [<?php echo yourVariable;?>],
                            data: [<?php echo yourVariable; ?>],
                            backgroundColor: <?php echo yourColor; ?>
                          }               
                          ]
                    },
                    options: {
                        responsive: true,
                          ..............
                          .............
                          .........
</script>

enter image description here

Leave a comment