0

I am getting the data and labels for my ChartJs chart via ajax and I create an array out of this.

When I make a console.log, the array looks like it would be working, but the chart has no labels and no data.

I've found this question here, but it doesn't solved the problem.

Here is my code for the chartJs:

               config = {
                    type: 'bar',
                    data: {
                        labels: labels,
                        datasets: [{
                            label: "Aufrufe",
                            data: dataarray,
                            backgroundColor: 'rgba(0, 188, 212, 0.8)'
                        }]
                    },
                    options: {
                        responsive: true,
                        legend: false
                    }
                }

and the arrays that I get from console.log:

enter image description here

That's how I create the array:

/* create a labels array */
                        while(year !== (new Date).getFullYear() || month !== enddate) {
                            console.log(year, month);
                            labels.push(month + " " + year);
                            month++;
                            if(month === 13) {
                                year++;
                                month = 1;
                            }

                        }

But the chart is simply an empty chart...

1 Answer 1

0

The issue was that the Ajax request was async. So the chart was drawn without any data.

The ajax request has to have async: false, so the data can be loaded and after that the chart draws with the data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.