1

there is no documentation of chart.js regarding the connection of getting the data from the database, that is why i'm still curious of how to implement my bar graph from an external graph data. and as of now i'm using codeigniter framework and i dont think CI do have library of chart graph. so in second thought how would i implement properly the graph in my framework. so first i loaded an offline chart.js:

<script src="<?php echo base_url('assets/js/Chart.min.js')?>"></script>

next i implement the bar chart with fixed data:

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'bar',
        data: {
            labels: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
        datasets: [{
            label: "Monthly Percentage of Project Completion",
        backgroundColor: 'rgb(3, 0, 102)',
            data: [90, 10, 5, 2, 20, 30, 45, 35, 56, 45, 2, 100],
                 }]
            },
        options: {}
        });

how do i get my database data to show in my barchart graph? enter image description here

and also want to have this scenario where my datasets will be dependent on my year data 2017,2018,2016 or more years to come and the percentage will be on the left side. enter image description here

Hanthony Tagam
  • 111
  • 3
  • 13
  • 1
    maybe you need to check this question: https://stackoverflow.com/questions/30928840/chart-js-getting-data-from-database-using-mysql-and-php – Sulyman Aug 14 '17 at 11:17
  • thanks for the link @Sulyman i will try these and update if i will face some problems. – Hanthony Tagam Aug 14 '17 at 11:44

1 Answers1

1

the main idea is to change the static data to dynamic data from database so when you have the data in a variable pass it istead of the static one. and it depends on the language you are using

Sulyman
  • 440
  • 5
  • 14