Data column(s) for axis #0 cannot be of type string in google chart dashboard: What’s happened?

When you are generating a google chard dashboard, have you ever got the Data column(s) for axis #0 cannot be of type string in google chart dashboard error? If the error occurs and you don’t know how to tackle it, the blog today will give you some solutions to deal with it. So, let’s try to find the most suitable way now!

How to fix the Data column(s) for axis #0 cannot be of type string in google chart dashboard issue?

As you know, if you want to draw and showcase a chart effectively, the data series have to be typed number and the x-axis data should be typed string. You split a string into an array, thus all the elements of the array must be strings. For example, you are using numeric data, it’s a good idea for you to change the line:

longArray.push(temp3[0]);

into:

longArray.push(parseFloat(temp3[0]));

In case all your data is integers, let’s use the following code:

longArray.push(parseInt(temp3[0], 10));

Moreover, you can also address the trouble by defining the column data types, such as:

var longArray = [
{label: 'Year', type: 'number'},
{label: 'Positive', type: 'number'},
{label: 'Negative', type: 'number'},
{label: 'Neutral', type: 'number'},
{label: 'Comments', type: 'string'},
{label: 'Status', type: 'string'},
{label: 'Score', type: 'number'}
];

When you input the data, you can do some crude type detection with the following code:

for(var i=0; i<temp.length; i++){
temp2 = temp[i].split(',');
if(temp2.length == 7){
for(var j=0; j<temp2.length;j++){
// this does nothing except make temp2[j] into a 1-element array
// temp3[0] === temp2[j], since you split on ',' already
temp3 = temp2[j].split(',');
if (temp3[0] == parseInt(temp3[0])) {
longArray.push(parseInt(temp3[0]));
}
else if (temp3[0] == parseFloat(temp3[0])) {
longArray.push(parseFloat(temp3[0]));
}
else {
longArray.push(temp3[0]);
}
}
}
}

In case you tried one of these methods above but the error still appears, you can combine the second and third ways to solve that.

Data column(s) for axis #0 cannot be of type string in google chart dashboard – Ending

To sum up, we have already given you some solutions to fix the trouble. Therefore, we wish the blog today will be useful for you. If you have more effective methods or have any difficulties, don’t hesitate to share them with us by leaving your comment below. Thanks for your reading and sharing. Have a great day!

5/5 - (2 votes)
Lt Digital Team (Content &Amp; Marketing)

Summer Sale Grab 50% Off for everything on today, don't miss it. Coupon code: SUMMER2024 Redeem Now
Summer Sale Grab 50% Off for everything on today, don't miss it. Coupon code: SUMMER2024 Redeem Now