fxcosta / laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel 5.x using Chartjs v2 library
485 stars 113 forks source link

chart render in success function of ajax call #75

Open Naveedali1234 opened 6 years ago

Naveedali1234 commented 6 years ago

Hello fxcosta and thank you so much for the amazing work.

actually this library is working perfectly when i return the $chartjs object from controller to view directly and render it there, but i am now doing it through ajax call, i have the chartjs object ready there in controller and return the object from the controller function to the ajax call success function, but how do i render in the success function of ajax call? your help would be really appreciated.

thank you

moh586 commented 5 years ago

Hello fxcosta and thank you so much for the amazing work.

actually this library is working perfectly when i return the $chartjs object from controller to view directly and render it there, but i am now doing it through ajax call, i have the chartjs object ready there in controller and return the object from the controller function to the ajax call success function, but how do i render in the success function of ajax call? your help would be really appreciated.

thank you

hi.do you find a solution for your problem?i have same problem

abedputra commented 3 years ago

Hi, any solution?

abedputra commented 3 years ago

I found a solution. I try to implement some functions like this. After calling the ajax, we will add the data from ajax to update our Chart with this function

function addData(chart, data, datasetIndex) {
    chart.data.datasets[datasetIndex].data = data;
    chart.update();
}

function addLabel(chart, label) {
    chart.data.labels = label;
    chart.update();
}

This is an example addData(chart, newData, 0); or addLabel(chart, newLabel);.