[Chartjs]-Loop through each tooltips to add different TimeStamps

1👍

been looking into some documentations and asking for some help about array and came across this pretty easy solution:
Pass the PHP array to javascript array:

var date = <?php echo json_encode($yourVariabel) ?>
//In my case:
var date = <?php echo json_encode($tempo) ?>

This is how you can print values to each label:

tooltips: {
              enabled: true, //Add this true
              mode: 'single', //Add this single
              callbacks:{
//Dont need this title stuf if dont want to
                title: function(tooltipItem, data) {
                    return data.labels[tooltipItem[0].index];
                },
//This is the good part:
                afterTitle: function(tooltipItem, data) {
                  var date = <?php echo json_encode($tempo) ?>

                  return date[tooltipItem[0]['index']]; 
                },
//Dont need this title stuf if dont want to
                label: function(tooltipItem, data) {
                      var label = data.datasets[tooltipItem.datasetIndex].label || '';                  
                      if (label) {
                          label += ': ';
                      }
                      label += (tooltipItem.yLabel)+"A";                  
                      return label;
                }
              }
            },

Leave a comment