[英]Custom tooltip in Chart.js
I'm trying to display custom tool tips with Chart.js depending on the data classification. 我试图根据数据分类显示Chart.js的自定义工具提示。
I want to display: 我要显示:
1: Tooltip1 1:工具提示1
2: Tooltip2 2:工具提示2
3: Tooltip2 3:工具提示2
Following is the code. 以下是代码。
<script type="text/javascript" language="javascript">
var pieData = [
{
value: parseInt(document.getElementById("<%= txtPendingCount.ClientID %>").value, 0),
color: "#f5170a",
highlight: "#f85248",
label: "1"
},
{
value: parseInt(document.getElementById("<%= txtCompletedCount.ClientID %>").value, 0),
color: "#ce5e0c",
highlight: "#cf7d40",
label: "2"
},
{
value: parseInt(document.getElementById("<%= txtWithheldCount.ClientID %>").value, 0),
color: "#f4cd0c",
highlight: "#f7de62",
label: "3"
}
];
window.onload = function () {
var ctx = document.getElementById("chart-area").getContext("2d");
window.myPie = new Chart(ctx).Pie(pieData);
};
</script>
Can anyone please suggest how to do this? 有人可以建议如何做吗?
Thanks. 谢谢。
In the example you can see how to do this, you can note that i use doughut but is the same idea to do this with pie chart: 在示例中,您可以看到如何执行此操作,您可以注意到我使用doughut,但使用饼形图是相同的想法:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <canvas id="chart-area" style="display:inline;"></canvas> <script> var doughnutData = [ { value: 200, color: "#FFF", label:"White", }, { value: 200, color: "#bb2028", label:"Red", }, { value: 80, color: "#d97128" , label:"Orange", }, { value: 40, color: "#fada09", label:"Yellow", }, { value: 100, color: "#6bb345", label:"Light Green", }, { value: 60, color: "#b4aea7", label:"Gray", }, { value: 200, color:"#2d5f2e", fillColor:"#2d5f2e", label:"Green", } ]; window.onload = function(){ var helpers = Chart.helpers; var canvas= document.getElementById("chart-area"); var ctx = canvas.getContext("2d"); var globalChartConfig = { responsive : true, tooltipTemplate: "<%if (label){%>Label Color: <%=label%>: <%}%> <%= value %>", } window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, globalChartConfig); }; </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.