2016-04-27 76 views
0

我正在使用Chart.js 2.0 公式:失敗率:失敗計數/總計數。 我有一個失敗率,失敗計數和總數的數組。Chart.js自定義工具提示以顯示更多數據

在折線圖中繪製組件對時間的失敗率很簡單,但現在我還希望在用戶將鼠標懸停在工具提示上時顯示失敗計數和總計數。我無法弄清楚如何定製它。

我們e.time,e.count,e.failure_count,e.rate

new Chart(document.getElementById(event_id).getContext("2d"), {type: "line", data: 
        { 
         labels: e.time, 
         datasets: [ 

          { 
           label: "Failure Rate", 
           fill: false, 
           borderColor: "#4caf50", 
           backgroundColor: "#4caf50", 
           pointBorderWidth: 1, 
           pointHoverRadius: 3, 
           data: e.rate 
          } 
         ] 
        }, options: { 
         scales: { 
          yAxes: [{ 
           ticks: { 
            suggestedMin: -1, 
            suggestedMax: 6 
           } 
          }] 
         }, 
         tooltips: { 
          custom: function(tooltip) { 
           tooltip.text= "Not working????" 
          } 
         } 
        } 
       }); 

回答

2

在2.0,回調需要一個回報。 所以基本上你想要做的是:

custom: function(tooltip) { 
    tooltip.text= "Not working????" 
} 

通過

callbacks: { 
    label: function(tooltipItem, data) { return "What you want as a tooltip" } 
} 
相關問題