Chartjs-Why do literal arrays work, but not coded arrays?

0πŸ‘

βœ…

It seems likely that whatever you are passing to your constructor for labels and data is not in the correct form. For us to help identify exactly what your issue is, you will have to show us the code you are using to create those data structures.

If you do it like this, it will reproduce what was in the sample code:

// array of names
var names = ["January","February","March","April","May","June","July"];

// array of objects
var items = [
        {
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,1)",
            pointColor : "rgba(220,220,220,1)",
            pointStrokeColor : "#fff",
            data : [65,59,90,81,56,55,40]
        },
        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [28,48,40,19,96,27,100]
        }
    ];


function ChartDataObject(labels, datasets)
{
    this.datasets = datasets;
    this.labels = labels;
}

var obj = new ChartDataObject(names, items);
// now obj should be in the same form as the data variable in the sample code

Leave a comment