0

I want to make a line chart whith googlechart ( https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart ). But i'm not able to format the array for the chart.

The array must looks like this :

var data = google.visualization.arrayToDataTable([
  ['Year', 'Sales', 'Expenses'],
  ['2004',  1000,      400],
  ['2005',  1170,      460],
  ['2006',  660,       1120],
  ['2007',  1030,      540]
]);

And I'm trying to make it that way :

var data = google.visualization.arrayToDataTable([['Year', 'Marque1', 'Marque2', 'Marque3', 'Marque4']]);
var i=1;
msg.forEach(function(entry) {               
    data.addRows([
      ['2004',  i-1,      0,      i,      6],
      ['2004',  i,      0,      i,      6],
      ['2004',  i+1,      0,      i,      6]
    ]);                 
    i++;
});

It's not the real values but i'll set them when i'll be able to make an array.

I have this error in the browser console when I run :

Uncaught Error: Type mismatch. Value 0 does not match type string in column index 1 

When I put some strings instead, google send me a error message instead of the chart :

Data column(s) for axis #0 cannot be of type string
2
  • Why don't you fill in the array and then call google.visualisation.arrayToDataTable() with the complete array? Commented Oct 30, 2014 at 9:24
  • It's a good idea but I don't know how to fill the array ... I tryed like that, jsfiddle.net/yqrj42f5 and I have " undefined is not a function " Commented Oct 30, 2014 at 9:40

1 Answer 1

2

I don't know if I got what you mean, but try this:

var rows = new Array();
rows.push(new Array('Year', 'Marque1', 'Marque2', 'Marque3', 'Marque4'));
var i = 1;
msg.forEach(function(entry) {
    rows.push(new Array(5, 5, 5, 5, 5)); // replace it with your values
}
var data = google.visualization.arrayToDataTable(rows);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.