1

This is the code which i have used for chart with php. How to make "data: [28, 48, 40, 19, 86, 27, 90, 20, 80, 81, 56, 55,]" which is script to php. I want send data as php variable.

<script>
     $(document).ready(function() {

         var lineData = {
             labels: ["January", "February", "March", "April", "May", "June", "July", "AUG", "SEP", "OCT", "NOV", "DEC"],
             datasets: [
                 {
                     label: "Sale",
                     backgroundColor: "rgba(26,179,148,0.5)",
                     borderColor: "rgba(26,179,148,0.7)",
                     pointBackgroundColor: "rgba(26,179,148,1)",
                     pointBorderColor: "#fff",
                     data: [28, 48, 40, 19, 86, 27, 90, 20, 80, 81, 56, 55,]
                 },

             ]
         };

         var lineOptions = {
             responsive: true
         };


         var ctx = document.getElementById("lineChart").getContext("2d");
         new Chart(ctx, {type: 'line', data: lineData, options:lineOptions});

     });
  </script>
Gowri Shankar
  • 93
  • 1
  • 7
  • If you're talking about converting a string response from a PHP script that is "data: [28, 48, 40, 19, 86, 27, 90, 20, 80, 81, 56, 55,]" to a usable array of numbers by javascript, use JSON.parse(the_PHP_string) – Bertrand May 30 '18 at 07:56

0 Answers0