如何动态更改jqplot渲染器? [英] How to dynamically change jqplot renderer?

查看:102
本文介绍了如何动态更改jqplot渲染器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我希望用户能够通过单击下拉菜单来更改图形的类型:BarRenderer,PieRenderer等.数据是相同的.我知道我可以在同一元素上再次调用$ .jqplot(),但随后我将不得不再次传递所有设置.而且我的页面上有可变数量的图形,这使该选项成为非常糟糕的选择.

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.

我找到了有关此链接: http://groups .google.com/group/jqplot-users/browse_thread/thread/efe6511cd9496f16/5c625baf78d3b0ae ,但看来我仍然必须再次调用$ .jqplot().

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.

是否有更好的方法可以做到这一点?还有一个小问题:是我一个人,还是jqplot上的文档不好?我必须遍历多个地方才能找到所需的选项(有时,该选项未记录在案,或者我无法以某种方式找到它).您如何学习如何使用jqplot?

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?

推荐答案

我认为文档还可以,但是您会在其中找到隐藏的功能或未记录的怪癖. IIRC(已经有一段时间了),您将不得不再次调用$ .jqplot(),但是您首先需要.empty()您的目标,否则您将获得额外的/混乱的画布.

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

这篇关于如何动态更改jqplot渲染器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆