2013-06-26 20 views
5

當我將鼠標懸停在累積折線圖上的行上時,我會在某個y時間收到工具提示消息x值。我想編輯此消息並添加更多內容。在nvd3的cumulativeLineChart上的自定義工具提示

因爲在我的values數組中,我有包含{X:x,Y:y,z:z,Dt:date}的json我希望在日期顯示列出X/Y/Z的自定義消息。

+0

您可以嘗試在[cumulativeLineChart.js](https://github.com/novus/nvd3/blob/master/src/models/cumulativeLineChart.js#L25)中對其進行編輯。在**第25行**中添加字符串。可能不是最好的方式,但解決您的問題。 – shabeer90

回答

2

如果你還沒有找到妥善的解決辦法呢,在這裏,你試試這個 -

nv.addGraph(function() { 
    var chart = nv.models.cumulativeLineChart().x(function(d) { 
     return d[0] 
    }).y(function(d) { 
     return d[1] 
    }).color(d3.scale.category10().range()).tooltip(function(key, x, y, e, graph) { 
     return '<h3>' + key + ' Custom Text Here ' + x + '</h3> here' + '<p> or here ,' + y + '</p>' 
    }); 
}); 

希望它能幫助。

+2

太棒了,這對我來說非常合適。只需添加一些信息,每個數據節點的附加數據就可以通過'e'參數訪問,e.point.Z會得到Z的值。 – Andrei

6

我使用的是nvd3 veraion 1.1.15b。

調用.tooltip()我沒有工作,但調用.tooltipContent()沒有,如下面的代碼:

 var chart = nv.models.pieChart() 
      .x(function (d) { return d.file; }) 
      .y(function (d) { return d.size; }) 
      .tooltipContent(function (key, y, e, graph) { 
       return '<h3>' + key + '</h3>' + 
        '<p>' + e.value.toSizeFmt() + '</p>'; 
      }) 

由於Andrei指出上述情況,e參數提供訪問原始值,以便可以格式化他們,而不是與已經格式化文本的y一起工作。希望這可以幫助!