2010-08-06 46 views
0

我需要知道如何使用Flot很容易地將另一個系列添加到現有的地塊。用flot添加另一個系列到現有的地塊

這裏是我目前正在繪製一個系列:

function sendQuery() { 
    var host_name = $('#hostNameInput').val(); 
    var objectName = $('#objectNameSelect option:selected').text(); 
    var instanceName = $('#instanceNameSelect option:selected').text(); 
    var counterName = $('#counterNameSelect option:selected').text(); 
    $.ajax({ 
     beforeSend: function() { 
      $('#loading').show(); 
     }, 
     type: "GET", 
     url: "http://okcmondev102/cgi-bin/itor_PerfQuery.pl?machine=" + host_name + "&objectName=" + objectName + "&instanceName=" + instanceName + "&counterName=" + counterName, 
     dataType: "XML", 
     success: function (xml) { 
      var results = new Array(); 
      var counter = 0; 


      var $xml = $.xmlDOM(xml); 
      $xml.find('DATA').each(function() { 
       results[counter] = new Array(2); 
       results[counter][0] = $(this).find('TIMESTAMP').text(); 
       results[counter][1] = $(this).find('VALUE').text(); 
       counter++; 
      }); 

      plot = $.plot($("#resultsArea"), [{ 
       data: results, 
       label: host_name 
      }], { 
       series: { 
        lines: { 
         show: true 
        } 
       }, 
       xaxis: { 
        mode: "time", 
        timeformat: "%m/%d/%y %h:%S%P" 
       }, 
       colors: ["#000099"], 
       crosshair: { 
        mode: "x" 
       }, 
       grid: { 
        hoverable: true, 
        clickable: true 
       } 

      }); 
+1

能否請您解決您的代碼的縮進?很難閱讀空間和括號到處。 – Scharrels 2010-08-06 19:21:21

回答

1

你可以只添加一個結果集:

// build two data sets 
var dataset1 = new Array(); 
var dataset2 = new Array(); 

var $xml = $.xmlDOM(xml); 
$xml.find('DATA').each(function(){ 
    // use the time stamp for the x axis of both data sets 
    dataset1[counter][0] = $(this).find('TIMESTAMP').text(); 
    dataset2[counter][0] = $(this).find('TIMESTAMP').text(); 
    // use the different data values for the y axis 
    dataset1[counter][1] = $(this).find('VALUE1').text(); 
    dataset2[counter][2] = $(this).find('VALUE2').text(); 
    counter++; 
}); 

// build the result array and push the two data sets in it 
var results = new Array(); 
results.push({label: "label1", data: dataset1}); 
results.push({label: "label2", data: dataset2}); 

// display the results as before 
plot = $.plot($("#resultsArea"), results, { 
    // your display options 
}); 
+0

對於results.push部分,使用JSON表示法(我認爲這就是它)是正確的。 我只是把結果數組做成全局的。我的查詢一次只能回收一個系列的數據,但我已經將其運行,謝謝! – 2010-08-06 19:24:46

0

在一個高的水平,你的電話到itor_PerfQuery.pl的結果將需要擴展到包括額外的序列數據。然後,您需要將「結果」變量變爲多維數組以支持附加數據,並且需要更新當前的xml「find」循環,以便相應地填充結果。代碼的其餘部分應該保持不變,因爲flot應該能夠繪製擴展數據集。我認爲flot example的審查將幫助你。祝你好運。

相關問題