title: chartjs how to update dynamically data from database(Chartjs cant get the data)
body: <p>I am so much new to chartjs and doing this current project with laravel. Now, I need to create a chart which needs to update automatically with no refresh and the data comes from mysql database.I found this kind of code online: <a href="https://codepen.io/jordanwillis/pen/bqaGRR" rel="nofollow noreferrer">https://codepen.io/jordanwillis/pen/bqaGRR</a> . I tried doing this code and the output always fails me.</p>
  
  <pre><code>   // used for example purposes
  function getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  
  // create initial empty chart
  var ctx_live = document.getElementById("mycanvas");
  var myChart = new Chart(ctx_live, {
    type: 'line',
    data: {
      labels: readingID,
      datasets: [{
        data: moist,
        borderWidth: 1,
        borderColor:'#00c0ef',
        label: 'liveCount',
      }]
    },
    options: {
      responsive: true,
      title: {
        display: true,
        text: "Chart.js - Dynamically Update Chart Via Ajax Requests",
      },
      legend: {
        display: false
      },
      scales: {
        yAxes: [{
          ticks: {
            beginAtZero: true,
          }
        }]
      }
    }
  });
  
  // this post id drives the example data
  var readingID = [];
  var moist = [];
  
  // logic to get new data
  var getData = function() {
    $.ajax({
      url: "/soildata",
      type:"GET",
      success: function(data) {
           console.log(data);
          data = JSON.parse(data);
  
  
        // process your data to pull out what you plan to use to update the chart
        // e.g. new label and a new data point
  
        // add new label and data point to chart's underlying data structures
        myChart.data.labels.push("ReadingID " + readingID++);
        myChart.data.datasets[0].data.push(getRandomIntInclusive(1, 25)); &lt;&lt;&lt;&lt;&lt;-----------I DONT KNOW HOW TO PLAY ON THIS PART I GUESS THIS PART CAN MAKE MY DATABASE WORKING
  
        // re-render the chart
        myChart.update();
      }
    });
  };
  
  // get new data every 3 seconds
  setInterval(getData, 3000);
  </code></pre>
  
  <p>I guess I need to make something on this function so that my data coming from my database will work properly:
   Chart.data.datasets[0].data.push(getRandomIntInclusive(1, 25));</p>
  
  <p>Anyone?..does anyone know about this?..I am a newbie on chartjs and truely I spent weeks in solving but I guess I cant.I hope someone out there could be a help, even a different code that will solve my problem is highly accepted. Thank you for any actions that will be taken..</p>