How to dynamically change jqplot renderer?
Basically, I want the user to be able to change the type of the graph by clicking a drop down menu: BarRenderer, PieRenderer, etc. The data is the same. I know I can call $.jqplot() again on the same element, but then I'll have to pass all the setting again. And my page have a variable number of graphs, which makes that option a very bad choice.
I found a link about this: http://groups.google.com/group/jqplot-users/browse_thread/thread/efe65开发者_StackOverflow社区11cd9496f16/5c625baf78d3b0ae but it seems I still have to call $.jqplot() again.
Is there a better way to do this? And one more small question: is it just me, or the documentation on jqplot is bad? I have to look through multiple places to find a option I want (and sometimes, the option isn't documented, or I couldn't find it somehow). How do you learn how to use jqplot?
I think the docs are ok, but you will find hidden features inside of it or quirks that aren't documented. IIRC (it's been a while) you will have to call $.jqplot() again but you first need to .empty() your target or you'll get extra / messed up canvases.
What you really need to do is save your data and allow it to be called later:
//This isn't real jqplot syntax but it should give you a good idea of what I'm explaining
var charts = [{name:"chart1",renderer:"pie",data:[[1,2],[2,3]]}]
$('#graph').jqplot(charts[0]);
//later
charts[0].renderer = "bar";
$('#graph').empty().jqplot(charts[0]);
精彩评论