2015-11-20 78 views
1

我想在工具提示中顯示文本「January」,然後顯示日期。在工具提示中顯示月份名稱

我應該怎麼做?不知道該怎麼做。

https://jsfiddle.net/bfn5u9go/

var data = { 
 
    labels: ["1", "2", "3", "4", "5", "6", "7"], 
 
    datasets: [{ 
 
     label: "My First dataset", 
 
     fillColor: "rgba(220,220,220,0.2)", 
 
     strokeColor: "rgba(220,220,220,1)", 
 
     pointColor: "rgba(220,220,220,1)", 
 
     pointStrokeColor: "#fff", 
 
     pointHighlightFill: "#fff", 
 
     pointHighlightStroke: "rgba(220,220,220,1)", 
 
     data: [65, 59, 80, 81, 56, 55, 40] 
 
    }, { 
 
     label: "My Second dataset", 
 
     fillColor: "rgba(151,187,205,0.2)", 
 
     strokeColor: "rgba(151,187,205,1)", 
 
     pointColor: "rgba(151,187,205,1)", 
 
     pointStrokeColor: "#fff", 
 
     pointHighlightFill: "#fff", 
 
     pointHighlightStroke: "rgba(151,187,205,1)", 
 
     data: [28, 48, 40, 19, 86, 27, 90] 
 
    }] 
 
}; 
 

 
window.onload = function() { 
 
    var ctx = document.getElementById("canvas").getContext("2d"); 
 
    window.myLine = new Chart(ctx).Line(data, { 
 
     responsive: true 
 
    }); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
 

 
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script> 
 

 
<div style="width:500px;"> 
 
    <div> 
 
     <canvas id="canvas"></canvas> 
 
    </div> 
 
</div>

回答

1

您應該使用tooltipTemplate選項:

var options = { 
    // String - Template string for single tooltips 
    tooltipTemplate: "<%= label %> January: <%= value %>" 
}; 

window.myLine = new Chart(ctx).Line(data, options); 

下面是示例:https://jsfiddle.net/wckfhrsa/7/

另外,查看更多工具提示選項global chart configuration