gpt4 book ai didi

javascript - 在工具提示中显示月份名称

转载 作者:行者123 更新时间:2023-11-27 23:39:32 24 4
gpt4 key购买 nike

我想在工具提示中显示文本“一月”,然后显示日期。

我该怎么做?不知道该怎么做。

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>

最佳答案

您应该使用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

关于javascript - 在工具提示中显示月份名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33820765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com