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' ?

  1. create graph, hide it
  2. chart.update() new data
  3. show graph

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -