动态创建 dojo 图表
嗨,我需要以这样的方式创建道场图表: 某些输入框中的系列值和图表发生变化 自动。因此,有了这个概念,我继续这样做:-
var showChart= function(){
var thevalue=dijit.byId('myvalue').get('value');//gets thevalue from the dijit numbertextbox
var chart1 = new dojox.charting.Chart2D("showgoals");
chart1.addPlot("default", {type: "Lines"});
chart1.addAxis("x");
chart1.addAxis("y", {vertical: true});
chart1.addSeries("Series 1", [thevalue, 2, 2, 3, 4, 5, 5, 7]);
chart1.render();};
然后每当值发生变化时我都会调用这个函数:-
dojo.connect(dojo.byId('myvalue'), "onchange",showChart);//whenever value changes the showChart function
被调用
html 看起来像这样:-
<div dojoType="dijit.layout.ContentPane" region="center">
<div id="showgoals" style="width: 250px; height:150px;" class="graph1"></div>
下面是更改值的文本框:-
<input id="myvalue" type="text" dojoType="dijit.form.NumberTextBox" name="myvalue"value="1000000" required="true"
invalidMessage="Only Numbers allowed"/><br/><br/>
我想要的是,每当此输入框中的值发生更改时, 函数 showchart 被调用,当前的绘图是 自动更改以显示新值,但发生的情况是 我完全得到了一张新图表,这看起来很自然......我会吗 如果是的话,必须销毁旧图表,然后重新创建新图表 请告诉我怎么做。
Hi I need to create dojo charts in such a manner that they take their
series values from certain input boxes and the chart changes
automatically.So with this concept I went ahead doing this:-
var showChart= function(){
var thevalue=dijit.byId('myvalue').get('value');//gets thevalue from the dijit numbertextbox
var chart1 = new dojox.charting.Chart2D("showgoals");
chart1.addPlot("default", {type: "Lines"});
chart1.addAxis("x");
chart1.addAxis("y", {vertical: true});
chart1.addSeries("Series 1", [thevalue, 2, 2, 3, 4, 5, 5, 7]);
chart1.render();};
Then I call this function whenever the value changes:-
dojo.connect(dojo.byId('myvalue'), "onchange",showChart);//whenever value changes the showChart function
is called
The html looks like this:-
<div dojoType="dijit.layout.ContentPane" region="center">
<div id="showgoals" style="width: 250px; height:150px;" class="graph1"></div>
The below is the text box which changes value:-
<input id="myvalue" type="text" dojoType="dijit.form.NumberTextBox" name="myvalue"value="1000000" required="true"
invalidMessage="Only Numbers allowed"/><br/><br/>
What I wanted was that whenever the value in this input box changes,
the function showchart gets called and the present plot is
automatically changed to show the new values, but what is happening is
that I get a new chart totally, which seems quite natural.. Will I
have to destroy the old chart and then recreate the new chart , if so
please tell me how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
showChart
函数中,每次使用new dojox.charting.Chart2D("showgoals")
调用该函数时都会创建一个新图表。如果要更新图表,可以调用updateSeries
更新系列数据,然后再次调用render()
更新图表。代码可能如下所示:
In the
showChart
function, a new chart is created every time the function is called usingnew dojox.charting.Chart2D("showgoals")
. If you want to update the chart, you can callupdateSeries
to update data of the series and callrender()
again to update the chart.The code may look like below: