您好我需要以这样的方式来创建图表道场它们采取其 从某些输入框系列值和图表的变化 automatically.So这个概念我继续这样做: -

  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被调用和本剧情 自动更改为显示新值,但正在发生的事情是 我得到完全是一个新的图表,这似乎是很自然..请问我 必须摧毁旧的图表,然后重新创建新的图表,如果是这样 请告诉我怎么了。

有帮助吗?

解决方案

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();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top