2011-10-11 22 views
3

如何在同一個絮圖中顯示兩個數據系列,當一個系列是一組點時,一個是一條線?在單個地圖上顯示點的數據集和線的數據集?

我已經seen examples of line series like this,但是複雜的因素是我想在同一個圖上顯示數據點數據線。

這似乎是一個相當常見的用例 - 基本上我想顯示一個散點圖及其最適合的線。

目前我有

var options = { 
     series: { 
      lines: { 
       show: false 
      }, 
      points: { 
       show: true 
      }, 
      lines: { 
       show: true 
      } 
     }, 
     grid: { 
      hoverable: true, 
     }, 
     yaxis: { 
      min: 0, 
      max: 1100000, 
      font: 'Georgia' 
     }, 
     xaxis: { 
      min: 10, 
      max: 480, 
      font: 'Georgia' 
     } 
     }; 
    var plot = $.plot($("#placeholder"), 
    [{ 
     data: scatterdata, 
     color: 'dodgerblue', 
    }], options); 
    var line = $.plot($("#placeholder"), 
    [{ 
     data: linedata, 
     color: 'black', 
    }], options); 

但這僅顯示第二組數據,而不是兩個都。

回答

3

你想要做這樣的事情(指定數據集合的一個在同一時間,有選擇):

$(function() { 

    var points = [[1, 6], [2, 3], [3, 9], [4, 2], [5, 11]]; 

    var fitLine = []; 
    for (var i = 0; i < 10; i += 0.5) 
     fitLine.push([i, (0.9 * i) + 3.5]); 

    $.plot($("#placeholder"), [ 
     { 
      data: points, 
      points: { show: true } 
     }, 
     { 
      data:fitLine, 
      lines: { show: true } 
     } 
    ]); 
}); 

產地:

enter image description here

相關問題