Chartjs-Chart.JS Bar Chart Throwing Error About Missing )

0πŸ‘

βœ…

I put your snipppet in http://jshint.com/ and I think you literally just need to remove the last curly brace – try the following:

Edit this snippet won’t actually run, I mean try this adjustment.

var ctx = document.getElementById('canvasone').getContext('2d');
var chart = new Chart(ctx, {
    data: {
        type: 'bar',
        labels: yoylabels,
        datasets: [{
                label: 'Dollar Values',
                backgroundColor: 'rgba(0, 129, 214, 0.8)',
                data: vals
            }]
    },
    options: {
        tooltips: {
            callbacks: {
                label: function (t, d) {
                        var xLabel = d.datasets[t.datasetIndex].label;
                        var yLabel = t.yLabel >= 1000 ? '$' + t.yLabel.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : '$' + t.yLabel;
                        return xLabel + ': ' + yLabel;
                    }
                }
            }
        },
        legend: {
            display: false,
            position: 'top',
        },
        scales: {
            yAxes: [{
                    ticks: {
                        beginAtZero: true,
                        callback: function (value, index, values) {
                            if (parseInt(value) >= 1000) {
                                return '$' + value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                            } else {
                                return '$' + value;
                            }
                        }
                    }
                }]
        }
    }
);

Leave a comment