2016-07-26 52 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; 
      } 

     }