javascript - ChartJS create chart Ajax -
i have followed example on chartjs website , have placed following code in window.onload:
ctx = document.getelementbyid("graphcanvas").getcontext("2d"); window.mybar = new chart(ctx).bar(barchartdata, { responsive : true });
... works fine when click button display popup window, bar chart dummy data shown.
in function have taken copy of dummy data , modified difference can seen.
in function have following code:
ctx = document.getelementbyid("graphcanvas").getcontext("2d"); window.mybar = new chart(ctx).bar(barchartdatadiff, { responsive : true });
... reason when code run popup window contained bar chart empty, bar chart disappears.
i have tried adding .destroy() before recreating chart , using 'mybar' instead of 'window.mybar' nothing seems work.
why don't create graph dummy data (hidden on load) , use chart js's update method insert data 'barchartdata' ?
- create graph, hide it
- chart.update() new data
- show graph
Comments
Post a Comment