动态创建 dojo 图表

发布于 2024-10-03 05:25:42 字数 1266 浏览 0 评论 0原文

嗨,我需要以这样的方式创建道场图表: 某些输入框中的系列值和图表发生变化 自动。因此,有了这个概念,我继续这样做:-

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞觅青森が 2024-10-10 05:25:42

showChart 函数中,每次使用 new dojox.charting.Chart2D("showgoals") 调用该函数时都会创建一个新图表。如果要更新图表,可以调用updateSeries更新系列数据,然后再次调用render()更新图表。

代码可能如下所示:

var chart1 = null;
var showChart = function() {
  var thevalue=dijit.byId('myvalue').get('value');
  if (!chart1) {
     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]);
  } 
  else {
     chart1.updateSeries("Series 1", [thevalue, 2, 2, 3, 4, 5, 5, 7]);
  }
  chart1.render();
}

In the showChart function, a new chart is created every time the function is called using new dojox.charting.Chart2D("showgoals"). If you want to update the chart, you can call updateSeries to update data of the series and call render() again to update the chart.

The code may look like below:

var chart1 = null;
var showChart = function() {
  var thevalue=dijit.byId('myvalue').get('value');
  if (!chart1) {
     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]);
  } 
  else {
     chart1.updateSeries("Series 1", [thevalue, 2, 2, 3, 4, 5, 5, 7]);
  }
  chart1.render();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文