2009-09-15 3 views
0

저는 AJAX 호출에서 appendData를 통해 피드 데이터 인 amcharts를 사용하고 있습니다. 이 호출은 2cos (x/2) + 2ln (ln은 줄 번호) 함수를 사용하여 Time.now를 X 및 8 행으로 렌더링하는 URL로 이동합니다. AJAX 요청은 1 초마다 이루어집니다.Amcharts 렌더링 데이터가 잘못되었습니다.

백엔드는 오류가 발생하는 중복 된 X가 아닌 한 항상 단일 점을 반환합니다. 오류로 인해 appendData가 완료되지 않으므로 appendData가 호출되지 않습니다.

누구든지 amcharts에 어떤 문제가 있는지 알 수 있습니까? 그것은 appendData (슬라이딩 윈도우를 시뮬레이트해야 함)에서만 문제가되는 것 같습니다.

자바 스크립트 코드는 아래와 같습니다. 이 페이지는 8 점의 그래프가있는 꺾은 선형 차트를 만들고이를 setup_chart_loader로 전달한다고 가정합니다. Netcordia.rapid_poller.updateChart는 Ajax 요청을 사용하여 차트를 업데이트하는 데 사용됩니다

Ext.ns("Netcordia.rapid_poller"); 

Netcordia.rapid_poller.refresh_rate = 1; //seconds 
Netcordia.rapid_poller.pause = false; //causes the AJAX to suspend 
Netcordia.rapid_poller.chart = null; 
Netcordia.rapid_poller.stop = false; 

/* This function does everything that is required to get the chart data correct */ 
Netcordia.rapid_poller.setup_chart_loader = function(chart){ 
    assert(Netcordia.rapid_poller.displaySizeInMinutes,"No display size"); 
    assert(Netcordia.rapid_poller.delta_url, "Data URL is empty"); 
    assert(Netcordia.rapid_poller.delta_params, "No Data params"); 

    if(typeof(chart) !== 'object'){ 
    chart = document.getElementById(chart); 
    } 

    Netcordia.rapid_poller.chart = chart; 

    // 5 seconds raw polling 
    var maxPoints = Netcordia.rapid_poller.displaySizeInMinutes * 60/5; 
    var count = 0; 
    var lastUpdate = ''; 

    debug("max number of points: "+maxPoints); 

    debug('creating updateChart function'); 
    Netcordia.rapid_poller.updateChart = function(){ 
    debug("Sending Data request"); 
    var params = {last: lastUpdate, max: 1}; //maxPoints}; 
    //I have to do this otherwise amcharts get a lot of data and only renders 
    // one item, then the counts is off 
    if(lastUpdate === ''){params['max'] = maxPoints;} 
    if (Netcordia.rapid_poller.pause){ 
     alert("pausing"); 
     params['historical'] = 1; 
     params['max'] = maxPoints; 
    } 
    Ext.apply(params, Netcordia.rapid_poller.delta_params); 

    //this might need to be moved to within the Ajax request 
    // incase things start piling up 
    if(!Netcordia.rapid_poller.stop){ 
     setTimeout(Netcordia.rapid_poller.updateChart,1000*Netcordia.rapid_poller.refresh_rate); 
    } else { 
     debug("skipping next poll"); 
     return; 
    } 

    Ext.Ajax.request({ 
     url: Netcordia.rapid_poller.delta_url, 
     baseParams: Netcordia.rapid_poller.delta_params, 
     params: params, 
     success: function(response){ 
     //if(Netcordia.rapid_poller.pause){ 
     // debug("Data stopped"); 
     // return; 
     //} 

     var json = Ext.util.JSON.decode(response.responseText); 
     lastUpdate = json.lastUpdate; 

     if(json.count === 0){ 
      debug("no data to append"); 
      return; 
     } 

     debug("appending "+json.count); 

     var remove = (count + json.count) - maxPoints; 
     if(remove <= 0){ remove = 0; } 
     count += json.count; 
     if(count > maxPoints){ count = maxPoints; } 

     debug("removing "+remove); 
     debug("count: "+count); 

     if(Netcordia.rapid_poller.pause){ 
      alert("Pausing for historical"); 
      //append a zero point and delete the existing data 
      // amcharts can leak extra points onto the screen so deleting 
      // twice the number is 
      chart.appendData("00:00:00;0;0;0;0;0;0;0;0",(count*2).toString()); 
      count = json.count; 
      remove = 1; 
      Netcordia.rapid_poller.stop = true; 
     } 

     chart.appendData(json.lines.toString(),remove.toString()); 
     } 
    }); 
    }; 
}; 

다음과 같이 데이터가 반환 레일 코드 :

def get_delta 
    max = 1 
    begin 
    current = Time.parse(params[:last]) 
    rescue 
    current = Time.now 
    end 

    if params[:historical] 
    max  = params[:max].to_i || 10 
    current = Time.at(current.to_i - (max/2)) 
    end 

    logger.info(current.to_i) 
    logger.info(max) 

    n = current.to_i 
    m = n+max-1 

    data = (n..m).collect do |x| 
    logger.info "For Point: #{x}" 
    point = Math.cos(x/2) 
    data = [Time.at(x).strftime("%H:%M:%S")] 
    for i in (1..8) 
     data.push(2*point+(2*i)); 
    end 
    data.join(";") 
    end 

    render :json => {count: data.size, lastUpdate: Time.now.strftime('%Y-%m-%d %H:%M:%S'), lines: data.join("\n")} 
end 

alt text

답변

1

는 버그가 보인다 Amcharts 자체에서.

Forum Post은 개발자의 답변입니다.

관련 문제