2014-10-31 46 views
2

我使用NVD3庫生成一個線型圖,並給出了一些數據:NVD3線型圖提示不按鼠標

screen shot 2014-10-31 at 13 39 44

screen shot 2014-10-31 at 13 40 25

問題是,交互指南顯示出來像這樣(特別注意工具提示):

screen shot 2014-10-31 at 13 35 10

screen shot 2014-10-31 at 13 35 19 請注意,我只在線圖的開始和結束處獲得工具提示。現在

,我設置useInteractiveGuideline(false)

screen shot 2014-10-31 at 13 34 59

這是否顯示正確,但很laggy,我想用useInteractiveGuideline(true)

懷疑這是我的代碼中的一個錯誤。

回答

2

也許你需要定義

.x(function (d) { 
    return xValues.indexOf(d.x); 
}) 

下面列出的代碼工作在我們的項目罰款:

nv.addGraph(function() { 
        var chart = nv.models.lineChart() 
          .margin({bottom: 20}) 
          .x(function (d) { 
           return xValues.indexOf(d.x); 
          }) 
          .useInteractiveGuideline(false) 
           .forceY([-10, 40]) 
          .tooltipContent(function (key, x, y, e) { 
           return '<h3>' + key + '</h3>' + 
            '<p>' + e.point.y + ' at ' + x + '</p>'; 
          }) 
         ; 

        chart.xAxis 
         //.axisLabel($translate.instant('loadTests.overview.testRuns.grid.startOn')) 
         .showMaxMin(true) 
         .tickFormat(function (d) { 
          if (typeof(d) === 'number' && d >= 0 && d < xValues.length) { 
           return d3.time.format('%m/%d')(new Date(1 * xValues[d])); 
          } 
          return 0; 
         }) 
         .tickValues(xValues) 
        ; 
... 

希望它能幫助! 如果你能爲此創建一個小提琴會更好。

+0

這幫了我。謝謝! – 2016-01-04 14:10:39