title: Display PHP Array in Chart.js tooltip
body: <p>I have a Bar Chart created with Chart.js. I get the data and labels from PHP Arrays which look like this:</p>
  
  <pre><code>for ($i = 0; $i &lt; count($mydata); $i++) {
      $labels .= "\"".$mylabels[$i] ."\"". ",\n" // "Label 1", "Label 2", "Label 3", ...
      $data .= $mydata[$i] . ",\n" // 34, 12, 64, 12, ...
  }
  </code></pre>
  
  <p>I then create the Chart using this code:</p>
  
  <pre><code>$chart = '
  &lt;script&gt;
  var data = {
      labels: ['.$labels.'],
      datasets: [
          {
              label: "My First dataset",
              fillColor: "rgba(220,220,220,0.75)",
              strokeColor: "rgba(220,220,220,1)",
              highlightFill: "rgba(221, 240, 242, 1)",
              highlightStroke: "rgba(204, 231, 234, 1)",
              data: ['.$data.']
          }
      ]
  };
  
  var ctx = document.getElementById("myChart").getContext("2d");
  
  new Chart(ctx).Bar(data, {
      scaleLabel : "&lt;%= value + \" €\" %&gt;",
      tooltipTemplate: "&lt;%= \"Project: \" + label %&gt;",
  });
  
  &lt;/script&gt;';
  print($chart);
  </code></pre>
  
  <p>This works fine so far but I need to display an Array inside the respective tooltip. So this line of code needs to be changed:</p>
  
  <pre><code>tooltipTemplate: "&lt;%= \"Project: \" + label %&gt;"
  </code></pre>
  
  <p>First I tried to display a PHP Variable inside it which looks like this:</p>
  
  <pre><code>tooltipTemplate: "&lt;%= '. $test .' \"Project: \" + label %&gt;"
  </code></pre>
  
  <p>EDIT: It seems I need to display the variable like this:</p>
  
  <pre><code>tooltipTemplate: " '. $test .'&lt;%= \"Project: \" + label %&gt;"
  </code></pre>
  
  <p>But how do I loop through an Array to display each element in the respective tooltip?</p>
  
  <p>My code is probably not so clean so I appreciate Tipps and Help from you as I am still learning to write clean code.</p>