2017-04-21 33 views
0

我看到這個post關於增加額外的數據到當前的數據。有沒有辦法在標籤/圖例中顯示這些附加數據以及數字數據?添加額外的數據到圖例Dypraphs

+0

嗨@Justine,在該職位你對此有何評論的信息,當用戶點擊一個點顯示。你是否想要完全的功能,或者你想要在圖例中始終顯示附加數據? –

+0

嗨@LucidioVacas :)但它只顯示在控制檯,當我嘗試'valueueFormatter:function(x){ return auxiliary [pt.idx]} – Justine

+0

但是當你點擊點或點擊時,你想顯示額外的信息鼠標結束了嗎? –

回答

1

您的代碼錯了,因爲您試圖以相同的方式使用來自其他帖子的代碼而沒有意識到差異。下一次,嘗試再調試一下你的代碼,在尋找失敗時做一些努力。

你說當你繪製輔助[x.idx]時,你會得到未定義的。如果你只是做了console.log(x),你會注意到x是時間戳值,一個整數,所以你不能獲得一個正確的索引來尋找數組中的額外數據。

如果看到dygraphs API,可以使用函數getRowForX(xVal),您可以使用該函數查找與x值相對應的行號。所以我在值格式化程序中使用了這個函數來獲取正確的索引來訪問數組中的其他數據。

我已經修改了你的代碼,我認爲它正在以你需要的方式工作。下面你有片段jsfiddle。我希望這對你有用。

var auxiliary = [ 
 
\t \t \t 'ID1', 
 
\t \t 'ID2', 
 
     'ID3', 
 
\t \t 'ID4', 
 
     'ID5', 
 
     'ID6' 
 
\t \t ]; 
 

 

 
new Dygraph(
 
document.getElementById("container"), 
 
    [ 
 
     [new Date("2016/2/3"), [1,3,6], [4,4,4]], 
 
     [new Date("2016/3/3"), [1,3,6], [3,3,3]], 
 
     [new Date("2016/4/3"), [1,3,6], [1,1,1]], 
 
     [new Date("2016/5/3"), [1,3,6], [2,2,2]], 
 
     [new Date("2016/6/3"), [1,3,6], [6,6,6]], 
 
     [new Date("2016/7/3"), [1,3,6], [5,5,5]] 
 
    ], 
 
{ 
 
    labels: [ "Date", "SD" , "Scatter"], 
 
    showRangeSelector: true, 
 
    customBars: true, 
 
    drawPoints: true, 
 
    series: { 
 
     "SD" : { 
 

 
     }, 
 
     "Scatter" : { 
 
      customBars: false, 
 
      strokeWidth: 0.0 
 
     } 
 
\t }, 
 
    axes: { 
 
     x: { 
 
\t \t \t valueFormatter: function() { 
 
     index = this.getSelection(); 
 
\t \t \t \t return auxiliary[index]; 
 
\t \t \t } 
 
\t \t }, 
 
\t includeZero: true 
 
\t } 
 

 
} 
 
);
<link href="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined-dev.js"></script> 
 
<div id="container" style="width:600px; height:300px;"></div>

+0

明白了。謝謝:) – Justine

+0

不客氣!無論如何,如果你認爲我的答案是有效的,請接受它;) –

相關問題