Home forums Using CanvasJS What can cause axisX and axisY to be undefined? Reply To: What can cause axisX and axisY to be undefined?

#24278

I found this due to a problem with “undefined” values showing up in the axis for some values – either by default or by zooming.

The problem had to do with the zoom level intervals and whether data existed in my values array for the axis specific to the label formatter.

After a bit of debugging – I found that the canvas.js lib was computing the interval automatically (fine) – but the calculated location for the e.value was sometimes a floating number instead of a perfect integer.

Since the array values can be found by their integer index position, the floating number was throwing an “undefined” value back to the labelFormatter. Hence “undefined” was showing up in the axis for the auto-computed intervals on the chart.

To fix this — I used the following code for my labelFormatter.

Note — the (e.value % 1 === 0) is a test to see if the e.value is an integer — if not a empty string is returned.

axisX: {
labelAngle: 90,
labelFormatter: function (e) {
if (e.value % 1 === 0) {
if (typeof xAxisValsArr[e.value] !== “undefined”) {
return xAxisValsArr[e.value];
}
} else {
return “”;
}
}
},
axisY: {
labelFormatter: function (e) {
if (e.value % 1 === 0) {
if (typeof yAxisValsArr[e.value] !== “undefined”) {
return yAxisValsArr[e.value];
}
} else {
return “”;
}
}
},

Hope this helps someone that also struggled with this… If anyone has any other suggestions, please reply.

————
SimilarParts.ai
Dave