The addRows() method in Google charts seems to be stubborn when it comes to accepting arrays as input

Attempting to create a line chart, but facing an error with Google Charts when trying to add a row of data:

Error: Every row given must be either null or an array. @ ...corechart.I.js:162

Below are sample columns I attempted to use. Columns are set up successfully and the graph is displayed blank until I attempt to input any rows.

var data = new google.visualization.DataTable();
        data.addColumn('number', 'timestamp');
        data.addColumn('number', 'JPY');
        data.addColumn('number', 'EUR');
        data.addColumn('number', 'SEK');
        data.addColumn('number', 'HKD');
        data.addColumn('number', 'CHF');
//All good so far

No matter how I try to pass an array using addRows(), the error persists. Similar queries on this issue didn't solve it due to code syntax errors or different approaches used in passing the code. Here's a simplified test case that still doesn't work.

data.addRows([1,2,3,4,5,6]); //Disrupts the chart

I also attempted:

var myrow = new Array(1,2,3,4,5,6);
data.addRows(myrow);

I've tried multiple arrays at once as well because most examples show passing multiple rows.

data.addRows([1,2,3,4,5,6],
             [7,8,9,10,11,12]);

Still encountering failures.

Answer №1

It's a simple fix. The addRows() method requires an array of arrays as input, not a single array for each row or separate parameters for every row. Check out the example in the documentation. To correct your code, it should be structured like this:

data.addRows([[1,2,3,4,5,6], [7,8,9,10,11,12]]);

You may find it easier to use the addRow() method instead, which handles one row at a time.

Answer №2

When I encountered a similar issue while adding rows with a for loop, I discovered that the documentation itself states that addRows() expects an array of arrays. What you're attempting to do can be accomplished simply by using addRow() without the 'S'.

addRow([1,2,3,4,5,6])

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can we determine in C++ whether the initial characters of a string are equivalent to another string?

I am working with an array of characters, which can be converted into a string when necessary. While the string may extend to a full sentence, my main focus lies on extracting just the first 6 characters. These initial characters represent the command act ...

Converting JavaScript values to C# code behind: A step-by-step guide

I'm facing a challenge where I need to retrieve JavaScript values in the code behind using C#. While I am aware that I can achieve this using hidden fields, there are no server controls on the page for postback. Can someone please advise me on how to ...

Inquiry about CSS Media Queries

I am facing an issue with CSS media queries... For my HTML page, I have separate files for desktop and iPad styles - desktop.css and ipad.css. In desktop.css, I have used @import url("ipad.css"); and added a @media not only screen and (device-width:768px) ...

Error: The function pathRegexp is not defined

While attempting to conduct tests on my project with jest, I encountered an error code that seems unrelated to the actual testing process. It appears to be more of a dependency or Node Express compatibility issue. `● Test suite failed to run TypeError: ...

PHP's ability to perform sorting on associative arrays in multiple ways is convenient

Let's take a look at this associative array: $arr = Array ( [banana] => 2 [cherry] => 1 [orange] => 3 [grapefruit] => 1 [apple] => 1 ) The goal is to sort it in a manner similar to the PLSQL term: A DESC, B ...

Currently, I am encountering a problem as I attempt to iterate through a dynamic table

I have a table containing various elements. An example row is Jack Smith with multiple rows like this: col1 col2 col3 col4 col5 col6 col7 col8 jack smith 23 Y Y error error_code error_desc The table is ...

Organizing Items in an Array/Vector to Form a Grid Pattern

I am looking to organize specific objects from a vector or array into a grid format. Currently, I have a method that does this when the objects are created. Here is the grid function I've developed: function ArrangeInGrid(uiRow:uint, uiCol:uint, iO ...

what is the method to incorporate an array of objects in a schemaless mongoose database?

**model schema** var mongoose = require('mongoose'); var Schema = mongoose.Schema; var itemSchema = new Schema({ name: {type: String, required: true}, price: {type: String} }); var objectSchema = new Schema({ name: {type: String, req ...

Error: SyntaxError - Received an unexpected % symbol when parsing

Currently, I am facing an issue with my page that has multiple embedded YouTube players. I need to listen for events on these players but encounter a strange error while using a solution mentioned in the answer found at Using Youtube's javascript API w ...

Issue with Custom Directive: Receiving Token Error for Expression in Isolated Scope in Angular

(The following messages, code snippets, etc, have been slightly altered for clarification) The error message received is as follows: Syntax Error: Token 'promiseObject' is unexpected, expecting [:] at column 3 of the expression [{{promiseObject ...

The comparison between form submission and AJAX request when transmitting data in JSON format

Working on a complex PHP/Drupal project, our team is facing the challenge of enabling a deep link into a page that requires extensive data to be passed from the originating site. We have full control over both ends so cross-domain issues are not a concern ...

The JSON file is not filling the options in the dropdown menu

procedure Add the objects from the dropdown into the dropdown menu. The Json file is located in root/ajax/.json and the working file is stored in root/.html. Problem: None of the objects from the JSON file are appearing in the dropdown menu. I attempted ...

Our JSON array property is not being parsed correctly by AngularJS

Upon receiving our GET request, the response is as follows: { "access_token": "pi7ID4bsZIC9yN ... 76gnblw", "token_type": "bearer", "expires_in": 1209599, "userName": "super0", "userRoles": "["member", "admin"]", ".issued": "Tue, ...

Convert the dynamic table and save it as a JSON file

Looking for the most effective method to save dynamic table data into JSON format. I have two tables that need to be saved into a single JSON file. While I can easily access and console log the regular table data, I'm having trouble retrieving the td ...

On the initial click of the button, the color will switch, and on the subsequent click,

I have created a basic HTML structure with a paragraph and a button. Upon clicking the button, I need different actions to take place. Specifically, on the first click, I want to change the color of the paragraph. On the second click, I aim to alter the fo ...

"Using enchant.js to create a game that utilizes an if statement to show a specific

I am looking to implement an if statement into my game that will display an html div (#game-over) once a certain score is reached. The div is currently set to "display:none". I have created a js fiddle for the game with the code $('#game-over'). ...

Using `$_POST` to accept a variable number of input fields for updating

Uncertain about the title for this query. Here is the objective: Page one features a form fetched from the database, with fields assigned unique IDs through a counting variable (e.g., header_1, header_2, header_3...). The number of fields is flexible as ...

Develop interactive div elements with the help of JavaScript/jQuery

Exploring dynamic div creation using javascript or jquery and looking for guidance. <div id="clickable"> <button class="start">Default</button> <button class="random">Randon</button> <button class="gradient"> ...

Unexpected behavior when using Async.map in conjunction with async.waterfall

Utilizing Async, I am using async.map() to connect my data array with a function and incorporating async.waterfall() within that function to execute functions in a series. However, the waterfall function is not functioning as anticipated. I have also attem ...

Is it possible to trigger an action in Vue Store using a Window/onunload event?

Currently, I am working on integrating an event listener for the `unload` event to trigger a Vuex store action that will help identify the ID of the closing window. This is crucial in our application where we need to manage the number of open tabs due to r ...