簡體   English   中英

NVD3累積折線圖顯示錯誤的y值

[英]NVD3 Cumulative line chart displays wrong y values

我已經將折線圖轉換為累積折線圖,並且其y值顯示不正確。 y軸的范圍應為80.00-140.00,但取而代之的是-0.08-0.20。 是否有人設法在下面調整其規范化代碼以使其適用於各種范圍?

 line.values = line.values.map(function(point, pointIndex) {

   point.display = {
     'y': (lines.y()(point, pointIndex) - v) / (1 + v)
   };
   return point;

 })

任何幫助將不勝感激。

我知道這個問題有些古老,但是我確信累積折線圖的規范化代碼在概念上不正確。 此外,NVD3累積折線圖實現實際上是索引圖實現( 請參閱Mike Bostock的示例 )。 我認為,累積折線圖更像這樣 使用NVD3折線圖和對基礎數據的一些快速修改,可以輕松實現累積圖。

如果我們認為Bostock是正確的,並且確實希望獲得索引折線圖,則應將NVD3中的indexify函數更改為:

/* Normalize the data according to an index point. */
function indexify(idx, data) {
    if (!indexifyYGetter) indexifyYGetter = lines.y();
    return data.map(function(line, i) {
        if (!line.values) {
            return line;
        }
        var indexValue = line.values[idx];
        if (indexValue == null) {
            return line;
        }
        var v = indexifyYGetter(indexValue, idx);

        // TODO: implement check below, and disable series if series
        // causes a divide by 0 issue
        if ((Math.abs(v) < 1e-6) && !noErrorCheck) {
            // P.S. You may have to set a higher threshold (~1e-6?).
            // I don't know I didn't run any tests...
            line.tempDisabled = true;
            return line;
        }

        line.tempDisabled = false;

        line.values = line.values.map(function(point, pointIndex) {
            point.display = {
                'y': (indexifyYGetter(point, pointIndex) - v) / v
            };
            return point;
        });

        return line;
    })
}

我向NVD3的作者詢問了一個相關問題 ,並計划提交請求請求。 請注意,僅當所有基礎數​​據為正時,百分比變化圖才真正有意義。 當您開始向組合中添加負值時,百分比變化將失去其所有含義。

我發現有效的方法是在點序列的開頭插入ay值為0的另一個點。

給定格式為[[x1,y1],[x2,y2],... [xn,yn]]的數據點列表,類似values.upshift([0,0])之類的東西對我有用( x值是任意的,但我只使用0或values [0] [0])插入到列表的前面。

(我在該圖表中得到了相同的結果。我仍在調查中,但希望能有所幫助。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM