2013-03-27 39 views
2

我試圖在我的flot圖表上使用一個不同的符號作爲我的一個數據系列,因爲它的規模比其他數據大得多。我使用這個例子作爲參考:http://www.flotcharts.org/flot/examples/symbols/index.html使用不同的符號繪製數據不起作用

這是我到目前爲止有:

我包括:

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.flot.js"></script> 
<script type="text/javascript" src="jquery.flot.symbol.js"></script> 

我再配置我海軍報的選項,如下所示:

var options = { 
     grid: {hoverable : true}, 
     xaxis: { mode: "time", timeformat: "%H:%M", tickLength: 1}, 
     series: { points : { show: true } } 
     }; 

然後我實際上繪製了數據:

$.plot('#placeholder', [{ 
       data: my_data, 
       lines: { show : true}, 
       points: { symbol: "square"}, 
       color: '#CB4B4B', 
       label: 'My Data' 
       }], options); 
     } 

但是,flot仍將圖形作爲默認圓圈。我得到的螢火沒有錯誤消息,我甚至都試圖在jquery.flot.symbol.js庫本身添加日誌消息,看看是否「方」處理程序甚至被稱爲像這樣:

var handlers = { 
      square: function (ctx, x, y, radius, shadow) { 
       console.log("Square handler was called"); 
       // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2 
       var size = radius * Math.sqrt(Math.PI)/2; 
       ctx.rect(x - size, y - size, size + size, size + size); 
      }, 

我越來越沒有控制檯消息等等我假設處理程序沒有正確調用。我在這裏錯過了什麼嗎?

編輯:

var d1 = [ 
[1364342400000, 208], 
[1364346000000, 107], 
[1364353200000, 42], 
[1364371200000, 1680], 
[1364360400000, 52], 
[1364349600000, 67], 
[1364385600000, 1118], 
[1364367600000, 163], 
[1364382000000, 1359], 
[1364378400000, 1468], 
[1364389200000, 1023], 
[1364356800000, 63], 
[1364374800000, 1601], 
[1364392800000, 556], 
[1364364000000, 84], 
], 
d2 = [ 
[1364342400000, 86], 
[1364346000000, 42], 
[1364353200000, 13], 
[1364371200000, 458], 
[1364360400000, 10], 
[1364349600000, 22], 
[1364385600000, 453], 
[1364367600000, 45], 
[1364382000000, 369], 
[1364378400000, 379], 
[1364389200000, 358], 
[1364356800000, 17], 
[1364374800000, 471], 
[1364392800000, 147], 
[1364364000000, 16], 
], 
d3 = [ 
[1364342400000, 7], 
[1364346000000, 5], 
[1364382000000, 11709], 
[1364371200000, 58336], 
[1364360400000, 1], 
[1364349600000, 1], 
[1364367600000, 2], 
[1364389200000, 1191], 
[1364378400000, 9085], 
[1364385600000, 4688], 
[1364374800000, 9386], 
[1364392800000, 1140], 
[1364364000000, 1], 
]; 

我還編輯我options參數和繪圖功能是如何叫:我想繪製的數據

var options = { 
grid: {hoverable : true}, 
xaxis: { mode: "time", timeformat: "%H:%M", tickLength: 1} 
}; 

$.plot("#placeholder", [{ 
data: d1, 
lines: { show : true }, 
points: { show: true}, 
color: '#EDC240', 
label: "d1" 
}, { 
data: d2, 
lines: { show : true }, 
points: { show : true}, 
color: '#AFD8F8', 
label: "d2" 
}, { 
data: d3, 
yaxis: 2, 
lines: { show : true}, 
points: { show: true, symbol: "square"}, 
color: '#CB4B4B', 
label: "d3" 
}], options); 

我也確信symbol庫被包含在內,因爲我已經將一些日誌本身添加到庫a nd顯示正常。

回答

4

我看不出您所做的事。我在這裏做了一個快速工作的例子:http://jsfiddle.net/ryleyb/shLtU/1/

我猜你沒有包括符號庫(即使你說你有)。

或顯示您的數據,可能在某種程度上是一個問題(可疑?)。

這是一個完整flot代碼,我跑去做工作示例(包括加海軍報和符號庫):

$.plot('#placeholder', [{ 
    data: [ 
     [1, 1], 
     [2, 3], 
     [4, 4], 
     [5, 9] 
    ], 
    lines: { 
     show: true 
    }, 
    points: { 
     show: true, 
     symbol: "square" 
    }, 
    color: '#CB4B4B', 
    label: 'My Data' 
}]); 
+0

感謝您的幫助迄今。我編輯了我的問題以包含更多信息,包括我試圖繪製的數據。我感到困惑,爲什麼它不工作,因爲我的代碼與上面的代碼很相似。 – 2013-03-27 18:50:15

+0

確實....即使有了這些增加的細節,它仍然不清楚是什麼問題 - http://jsfiddle.net/ryleyb/shLtU/2/顯示所有的更改,它仍然顯得很好... – Ryley 2013-03-27 18:53:42

+0

我應該檢查我運行的是什麼版本的「flot」。我使用的版本是'0.6',只要我升級到0.7,方形符號就可以很好地工作。你的回答讓我走上了正軌。感謝您的幫助! – 2013-03-27 19:15:02