How to dynamically change jqplot renderer?

…衆ロ難τιáo~ 提交于 2019-12-04 12:47:00

问题


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/efe6511cd9496f16/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?


回答1:


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]);


来源:https://stackoverflow.com/questions/7212922/how-to-dynamically-change-jqplot-renderer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!