Show only the required Labels - CanvasJS JavaScript Charts
Show only the required Labels - CanvasJS JavaScript Charts
by canvasjs
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
var chart = new CanvasJS.Chart("chartContainer",
{
axisX:{
interval : 10,
labelFormatter: function(e){
var dataPoints = e.chart.options.data[0].dataPoints;
for(var i = 0; i < dataPoints.length; i++){
if(dataPoints[i].x === e.value && dataPoints[i].forceShowLable)
return e.label;
}
return "";
}
},
data: [
{
type: "column",
dataPoints: [
{ label: "label1", x: 10, y: 71, forceShowLable: true },
{ label: "label2", x: 20, y: 55},
{ label: "label3", x: 30, y: 50, forceShowLable: true },
{ label: "label4", x: 40, y: 65 },
{ label: "label5", x: 50, y: 95, forceShowLable: true },
{ label: "label6", x: 60, y: 68 },
{ label: "label7", x: 70, y: 28, forceShowLable: true },
{ label: "label8", x: 80, y: 34 },
{ label: "label9", x: 90, y: 14},
{ label: "label10", x: 100, y: 14, forceShowLable: true },
{ label: "label11", x: 110, y: 71 },
{ label: "label12", x: 120, y: 55, forceShowLable: true },
{ label: "label13", x: 130, y: 50 },
{ label: "label14", x: 140, y: 65, forceShowLable: true },
{ label: "label15", x: 150, y: 95 },
{ label: "label16", x: 160, y: 68, forceShowLable: true },
{ label: "label17", x: 170, y: 28 },
{ label: "label18", x: 180, y: 34, forceShowLable: true }
]
}
]
});
chart.render();