0

How to read an array in PHP inside JavaScript? Like this

<?php
$f(0)=69;
$f(1)=8;
$f(2)=25;
$f(3)=5;
$f(4)=32;


?>

<script>
var barChartData = {labels : ["Ene","Feb","Mar","Abr","May","Jun","Jul"],
        datasets : [
    {
    fillColor : "#e64608", strokeColor : "#e64608",
    data:[65,59,90,81,56,55,40]
    },
    {
    fillColor : "#acadb1", strokeColor : "#acadb1", data :
    [28,48,40,19,96,27,100]
    }
    ]   
    }
    var myLine = new
  Chart(document.getElementById("bar").getContext("2d")).
  Bar(barChartData);
  </script>

I would like to replace the "data" in the data with the ones in the PHP array.

Pang
  • 9,564
  • 146
  • 81
  • 122
  • Please learn about how to use [Php `Array()`](http://php.net/manual/en/language.types.array.php#language.types.array.syntax.array-func) – Abdulla Nilam Sep 17 '15 at 05:43

1 Answers1

0

The best solution id to load data using ajax. Another option is to render data as follows.

<script>
var barChartData = <?php json_encode($array); ?>
</script>
Tismon Varghese
  • 849
  • 1
  • 6
  • 17