5/5 - (2 votes)

Are you struggling to get your Google Chart dashboard up and running? Are you stuck trying to figure out why your data column(s) for axis #0 cannot be of type string in google chart dashboard? You’re not alone! Fortunately, there is a simple solution that can help.

This blog post will walk you through how to easily fix this issue and get your chart dashboard up and running in no time!

Why did you get Data column(s) for axis #0 cannot be of type string in google chart dashboard?

This error message in a Google Chart Dashboard indicates that you are trying to use a string data type for the data column in your chart, but the chart is expecting a numeric data type.

Google Charts supports different data types for the columns, such as string, number, date, and so on. The type of data in a column determines how the chart will treat and display the data. If you try to use a string data type for a column that is expecting a numeric type, you will get this error.

How to address “Data column(s) for axis #0 cannot be of type string in google chart dashboard”

To resolve this error, make sure that the data in the column that you are using for the chart axis is of the correct type. 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, hence all the elements of the array must be strings. For example, if you are using numeric data, then you should change the line:

longArray.push(temp3[0]);

into:

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

In case, all your data is integers, let’s utilize the code below:

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

Another way is that 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'}
];

Once 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]);
}
}
}
}

Finally

Hopefully, with the 3 mentioned methods above, you can apply your error effectively. In case, your error still exists, let’s write down your situation in the comment below.

Further, you can drop by our website to explore a gallery of eye-catching, responsive, free WordPress Themes on our website.

Leave a Reply

Your email address will not be published. Required fields are marked *

Save 99% money with single purchase! Get All-In-One DEV package: Access all paid products! Unlimited Downloads with more than 300+ PRO items Sign Up Now!
Merry xMas & Happy New Year sale! Get 50% OFF for your purchase on today! Coupon code: XMASNEWYEAR Redeem Now