Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: cannot provide rows/columns separately to GeoChart #583

Open
1 task
khitrenovich opened this issue Apr 14, 2022 · 3 comments
Open
1 task

[Bug]: cannot provide rows/columns separately to GeoChart #583

khitrenovich opened this issue Apr 14, 2022 · 3 comments
Labels

Comments

@khitrenovich
Copy link

khitrenovich commented Apr 14, 2022

Would you like to work on a fix?

  • Check this if you would like to implement a PR, we are more than happy to help you go through the process.

Current and expected behavior

Consider the following data:

const columns = ["Country", "Popularity"];
const rows = [
  ["Germany", 200],
  ["United States", 300]
];

The following chart configuration results in "Incompatible data table: Error: Unknown address type." error:

    <Chart
      chartType="GeoChart"
      width="100%"
      height="400px"
      columns={columns}
      rows={rows}
    />

Providing data={[columns, ...rows]} instead of the separate rows and columns properties works as expected.

Note that this worked fine in pre-v4, so it was likely broken recently.

Reproduction

https://codesandbox.io/s/funny-tharp-6ymtob

react-google-charts version

v4

Possible solution

I suspect that the propagation of rows and columns down to GoogleChartDataTable is broken somewhere, so instead of the appropriate treatment the flow goes to the default option (which apparently creates invalid results for GeoChart). Yet, I wasn't able to trace through the code where it happens.

@khitrenovich khitrenovich changed the title [Bug]: cannot provider rows/columns separately to GeoChart [Bug]: cannot provide rows/columns separately to GeoChart Apr 14, 2022
@siljeschwermer
Copy link

I have the same issue after updating to v4.0.0 for other chart types with the error message "Table has no columns" (for example for the scatter plot in the "Initialize using rows and columns" example in the walkthrough). As you say, providing data={[columns, ...rows]} works, but initializing columns and rows separately causes an error.

@athermantis
Copy link

Ran into the same issue, appreciate the workaround though

@radek-kehar
Copy link

The problem is in the condition of the GoogleChartDataTable:

if (data !== null) {
  if (Array.isArray(data)) {
    dataTable = google.visualization.arrayToDataTable(data);
  } else {
     dataTable = new google.visualization.DataTable(data);
  }
} else if (rows && columns) {
  dataTable = google.visualization.arrayToDataTable([columns, ...rows]);
}

If I set only columns and rows to the Chart component, then the variable data is undefined. Rendering the graph goes through the first condition (i.e. data ! = null), rows and columns are not set.

Another workaround is to set the data to null:

<Chart
  chartType="Timeline"
  ...
  data={null}
  columns={columns}
  rows={rows}
/>

michmerr added a commit to michmerr/react-google-charts that referenced this issue Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants