2014-01-18 45 views
0

我有以下代码,我想要做的是更新图表,使用按钮按钮(也在页面启动时)从AJAX调用中获取值。我遇到的问题是图表不会更新或重新渲染。我已经硬编码了从服务器进来的值,只是作为一个测试,因为我知道我可以得到这些值。Dojo图不会重新渲染更新系列

require(["dojox/charting/Chart", 
       "dojox/charting/axis2d/Default", 
       "dojox/charting/plot2d/Lines", 
       "dojo/ready", 
       "dojox/charting/themes/Claro", 
       "dojo/request", 
       "dojo/dom", 
       "dojo/on"], 
      function(Chart, Default, Lines, ready, theme, request, dom, on){ 
      ready(function(){ 
       var policeResChart = new Chart("simplechart"); 
       policeResChart.addPlot("default", {type: Lines, enableCache:true}); 
       policeResChart.setTheme(theme); 
       policeResChart.theme.plotarea.fill = ""; 
       policeResChart.fill = "";//the broder around the chart 
       policeResChart.addSeries("data", policeResponses, {stroke:{color:"orange", width:3}}); 
       policeResChart.render(); 

       var myButton = dom.byId("btn"); 
       on (myButton, "click", function(evt){ 
        request.post("test.jsp", { 
         data:{ 
          color: "blue" 
         } 
         }).then(
         function(response){ 
          var newData = [ 
           { y: 1 }, 
           { y: 1 }, 
           { y: 1 }, 
           { y: 31 }, 
           { y: 1 }]; 

          policeResChart.updateSeries("data", newData); 
          policeResChart.render(); 

         }//end response 

        ); 

       });//end onclick 


     });//ends ready function 

    });//ends require 

最奇怪的是,只有1个render()可以被调用。例如,如果我将第一个(准备就绪)渲染出来并使用onclick渲染,它将起作用。我也注意到,在onclick中第二次渲染后,我放不下任何东西。所以在按钮推送中的第二次渲染之后提醒(“测试”)什么也不做。我不知道为什么。

回答

0

好吧,因为一些奇怪的原因,当我在policeResChart.fullRender();按钮按下这个工程。有人能解释为什么吗?我不完全明白为什么render()不起作用。无论如何,很高兴其“固定”。