2016-07-26 53 views
0

在下面的代碼中,我需要的工具提示是這樣的概率:40觀衆:5000即在工具提示中我需要xAxes標籤字符串與xAxes值和yAxes標籤字符串與yAxes value.How實現這個請幫助在chart.js中的自定義工具提示

var ctx = document.getElementById("myChart"); 
var myChart = new Chart(ctx, { 
type: 'line', 
data: { 
    datasets: [{ 
     label: 'Audience', 
     data: [{x:12,y:9000}, {x:30, y:6000}, {x:40, y:5000},{x:52,y:4000},{x:70,y:3000},{x:92,y:2000}], 
     backgroundColor: 'rgba(255, 99, 132, 0.2)', 

     borderColor: 'rgba(255, 159, 64, 1)', 
     borderWidth: 1 
    }] 
}, 
options: { 
tooltips: 
{ 
callbacks: 
{ 
label: function(tooltipItem, data) {return data.datasets[tooltipItem.datasetIndex].label+':'+ tooltipItem.yLabel; 
} 
} 
}, 
    scales: { 
    xAxes: [{ 
    type: 'linear',position: 'bottom', 
     scaleLabel:{labelString:"Probability",display:true}, 
      ticks: { 
       beginAtZero:true, 
       max:100 
      } 
     }], 
     yAxes: [{ 
     scaleLabel:{labelString:"Audience",display:true}, 
      ticks: { 
       min: 1000 
      } 
     }] 
    } 
} 
}); 

回答

0

只是這一個取代你的「回調」塊:

 callbacks: 
     { 
      title: function() { 
       return ''; 
      }, 
      beforeLabel: function(tooltipItem, data) { 
       return 'Probability: ' + tooltipItem.xLabel + '%'; 
      }, 
      label: function(tooltipItem, data) { 
       return data.datasets[tooltipItem.datasetIndex].label+': '+ tooltipItem.yLabel; 
      } 

     }