我已經解決了這個問題,在一定程度上,通過預先計算最大值
var data = [1,2,4/0,3,10,2,1,0/0,2,1]
var filtered = data.filter(a => !(a == Infinity || isNaN(a)))
var r = ['min', 'max'].map(name => Math[name]).map(f => f(...filtered))
new Dygraph(document.getElementById("demodiv"), data.map((d,i) => [i, d])
\t , {labels: ["Date", "series1"], valueRange:r});
<script src="http://dygraphs.com/dygraph-combined.js"></script>
<div id="demodiv"></div>
正如你看到的,我們必須在x = 2被簡單地忽略了無窮大。不過,我希望圖表顯示它會垂直向上超出「屋頂」以顯示無窮大。我不得不這樣做手工
var data = [1,2,4/0,3,10,2,1,0/0,2,1]
var filtered = data.filter(a => !(a == Infinity || isNaN(a)))
var r = ['min', 'max'].map(name => Math[name]).map(f => f(...filtered))
// map infinities to large numbers. These nums are too large for the displayed range and did not participate in visible range definition
//var m = new Map(); m.set(Infinity, Number.MAX_VALUE); m.set(-Infinity, Number.MIN_VALUE) // min/max are too large for the Dygraph
var m = new Map(); m.set(Infinity, 1e7); m.set(-Infinity, -1e7)
data = data.map(a => m.get(a) || a)
new Dygraph(document.getElementById("demodiv"), data.map((d,i) => [i, d])
\t , {labels: ["Date", "series1"], valueRange:r});
<script src="http://dygraphs.com/dygraph-combined.js"></script>
<div id="demodiv"></div>
然而,這使得另一個問題:值標籤也被轉換從Infinity
到1e7
。將鼠標懸停在圖上時,您會看到該值爲1e7
而非Infinity。