I have a PHP-array for the Javascript Library chart.js and it´s like this:
$array = [ 'options' => [ 'plugins' => [ 'tooltip' => [ 'callbacks' => [ 'label' => "function(context) { let label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.y !== null) { label += context.parsed.y + ' ' + '€'; } return label; }" ] ] ] ] ];
This PHP-array is requested by AJAX and in JavaScript I have:
new Chart(ctx, array);
array contains the data from the PHP-array.
The problem is the 'label'-element that contains a callback-function for JavaScript. The function does not work in this way. Is it possible to get this to work or do I have to bring the callback-function back to JavaScript and only request the relevant data ('€')? The callback-function isn´t static, so I thought it´s better to have it in PHP.