Chartjs-Extend chart.js in PHP heredoc causes parse error

1👍

I’m not sure why you’re having problems, I don’t think you should be.

But I have a better answer for you, use buffers instead of heredocs (they’re easier to work with anyway)

Google ob_start to learn how it works, they’re super useful

ob_start()?>
<script type="text/javascript">
var ctx = document.getElementById("myChart").getContext("2d");

Chart.types.Bar.extend({
    name: "myChart",
    initialize: function () {
        Chart.types.Bar.prototype.initialize.apply(this, arguments);
    }
});

new Chart(ctx).myChart(data, {
    scaleLabel : "<%= value + ' $' %>"
});

</script>
<?php $chart = ob_get_clean();
echo $chart;

Leave a comment