labelFormatter - Formatter for Crosshair Label on Axis X - 0 | JSFiddle Sample Code

labelFormatter - Formatter for Crosshair Label on Axis X - 0 | JSFiddle Sample Code

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>

<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div style="margin-top:16px;color:dimgrey;font-size:9px;font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration:none;">Source: <a href="https://canvasjs.com/docs/charts/chart-options/axisx/crosshair/label-formatter/" target="_blank" title="labelFormatter - Formatter for Crosshair Label on Axis X ">https://canvasjs.com/docs/charts/chart-options/axisx/crosshair/label-formatter/</a></div>

JavaScript

window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",{
	title: {
		text: "Using Custom Formatter function in Crosshair"
	},
	axisX: {
		crosshair: {
			enabled: false,
			snapToDataPoint: true,
		}
	},
	axisY: {
		crosshair: {
			enabled: true,
			snapToDataPoint: true,
			labelFormatter: function (e) {
				return "X Value: " + CanvasJS.formatNumber(e.value, "#,##0");
			}
		}
	},
	data: [{
		type: "spline",
		dataPoints: [
			{ y: 5 },
			{ y: 9 },
			{ y: 17 },
			{ y: 32 },
			{ y: 22 },
			{ y: 14 },
			{ y: 25 },
			{ y: 18 },
			{ y: 20 }
		]
	}]
});
    chart.render();
  setInterval(() => {
    chart.axisY[0].crosshair.showAt(17);
    chart.render();
  }, 1000);

}