Hide indexLabel if corresponding y value is zero - CanvasJS
Hide indexLabel if corresponding y value is zero - CanvasJS
by canvasjs
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
var chart= new CanvasJS.Chart("chartContainer", {
title:{
text: "Hide indexLabel if corresponding y value is zero"
},
data: [
{
type: "doughnut",
dataPoints: [
{ x: 10, y: 1, indexLabel: "dataPoint1" },
{ x: 20, y: 2, indexLabel: "dataPoint2" },
{ x: 30, y: 0, indexLabel: "dataPoint3" },
{ x: 40, y: 2, indexLabel: "dataPoint4" },
{ x: 50, y: null, indexLabel: "dataPoint5" },
{ x: 60, y: 0, indexLabel: "dataPoint6" }
]
}
]
});
function hideIndexLabel() {
var length = chart.options.data[0].dataPoints.length;
for( i = 0; i < length; i++ ) {
if( chart.options.data[0].dataPoints[i].y === 0 || chart.options.data[0].dataPoints[i].y === null ) {
chart.options.data[0].dataPoints[i].indexLabel = "";
}
else
chart.options.data[0].dataPoints[i].indexLabel = chart.options.data[0].dataPoints[i].indexLabel;
}
}
hideIndexLabel();
chart.render();