JSFiddle - React, Tailwind, and code Playground
=
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
JavaScript
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2", // "light1", "light2", "dark1", "dark2"
title:{
text: "Column Chart with Index Labels on Empty Data Points"
},
data: [{
type: "column",
showInLegend: true,
legendMarkerColor: "gold",
color: "lightblue",
indexLabelOrientation: "vertical",
legendText: "Hours",
dataPoints: [
{ y: 40, label: "Goal", color: "gold" },
{ y: 0, label: "SUN" },
{ y: 0, label: "MON" },
{ y: 0, label: "TUES" },
{ y: 0, label: "WED" },
{ y: 70, label: "THURS" },
{ y: 20, label: "FRI" },
{ y: 30, label: "SAT" }
]
}]
});
chart.render();
addEmptyIndexLabel();
function addEmptyIndexLabel() {
for(var i = 0; i < chart.options.data[0].dataPoints.length; i++) {
if(chart.options.data[0].dataPoints[i].y === 0) {
chart.options.data[0].dataPoints[i].indexLabel = "EMPTY"
}
chart.render();
}
}