GeoChart : addListener :WARNING Error: The specified column index is invalid. It must be an integer between 0 and 1

When clicking on a country in Google GeoChart, I am attempting to retrieve the name of that country but encountering an error when using addListener.

Explore my Stack Blitz demonstration here: https://stackblitz.com/edit/angular-advanced?embed=1&file=src/app/home/home.component.ts&hideExplorer=1&hideNavigation=1

Additionally, I'm wondering if there is a way to show the color axis bar with the region name corresponding to the selected color?

Answer №1

When using GeoChart, only the row index is returned for the column, with null being returned for the column itself.

To access the country name, always refer to column 0 (zero) as it will contain the country names.

Below is a functional code snippet:

google.charts.load('current', {
  'packages':['geochart'],
  // Note: you will need to get a mapsApiKey for your project.
  // See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
  'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
});
google.charts.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {
  var data = google.visualization.arrayToDataTable([
    ['Country', 'Popularity'],
    ['Germany', 200],
    ['United States', 300],
    ['Brazil', 400],
    ['Canada', 500],
    ['France', 600],
    ['RU', 700]
  ]);

  var options = {};

  var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));

  google.visualization.events.addListener(chart, 'select', selectHandler);

  function selectHandler() {
    var selectedItem = chart.getSelection();
    if (selectedItem.length > 0) {
      console.log(data.getValue(selectedItem[0].row, 0));
    }
  }

  chart.draw(data, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

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

What is the best way to reset a dropdown list value in angular?

Is there a way to erase the selected value from an Angular dropdown list using either an x button or a clear button? Thank you. Code <div fxFlex fxLayout="row" formGroupName="people"> <mat-form-field appearance=&quo ...

I'm looking to incorporate a module from another component (Next.js, React.js) into my project

I need to implement the "StyledSwiperPagination(swiper-pagination-bullet) at SwiperImages.tsx" in "index.tsx". The problem is that when I added <StyledSwiperPagination /> in index.tsx, nothing appeared on the screen. Lorem ipsum dolor sit amet, co ...

Save geometric shapes data in the SQLite database

How do I go about storing polygon data in an SQLite database? Important: I am utilizing the Cordova plugin. polygon: Point[]; interface Point { x: number; y: number; } https://i.sstatic.net/5EYf2.png ...

Crafting interactive buttons with angular material

I've been working on an angular application where I created 5 mat flat buttons using angular material. <button mat-flat-button [ngClass]="this.selected == 1 ? 'tab_selected' : 'tab_unselected'" (click)="change(1)">B-L1</b ...

How can I ensure that a list displaying data from an API is properly rendered in React.js using Vitest?

I have a component that displays a list fetched from a REST API using a useEffect hook without any dependencies. The fetched data is then stored in state. Here is the code snippet: import { useEffect, useState } from 'react'; import { fetchAllMed ...

What's the reason behind the inconsistency of the exports field in typescript and npm?

Our software development kit @ltonetwork/lto is built using typescript. We utilize the tsc compiler to convert the codebase into JavaScript files stored in the lib directory. Within the package, there are multiple sub-packages located in subdirectories, e ...

Guide to developing universal customized commands in Vue 3 using Typescript

I recently built my app using the Vue cli and I'm having trouble registering a global custom directive. Can anyone point out what I might be doing incorrectly here? import { createApp } from "vue"; import App from "./App.vue"; impo ...

Accessing a specific value based on a selected option in Angular 2+

Examining the Angular 2+ code snippet below, there is an Array defined in TypeScript: models = [{idModele: 1, model: "Bianca", price: 500}, {idModele: 2, model: "etc", price: 600} ] The query here is about setting up a mechanism where selecting a specifi ...

Issue: NG0900: Encountered an error while attempting to differentiate '[object Object]'. Only arrays and iterables are permitted

I'm currently working on the frontend development of a crud application. While implementing lazy pagination, I encountered an error Error: NG0900: Error trying to diff '[object Object]'. Only arrays and iterables are allowed I have search ...

Tips for passing configuration constants from HTML to a class in Angular 2 for reusing classes

Suppose I am looking to efficiently reuse my Angular 2 components, how can I input configuration directly into the HTML and then pass it to the respective class? However, could this method be vulnerable to potential manipulation in the HTML code by unautho ...

typescript issue with react's createContext when used with typescript

I'm attempting to integrate this toast manager into my React TypeScript application: https://codesandbox.io/s/react-toasts-melne?from-embed=&file=/src/contexts/ToastContext.js I've created a file named toast-context.tsx import React, { useC ...

What is the process for importing Firestore types into the utils file?

In the current logic, there is a function that handles specific data record processing stored in firestore: private listenUserData (): void { this.unListenUserData = FirebaseDb .collection(`users`).doc(this.user.id) .collection(`userData`) ...

methods for determining the child type of an interface in TypeScript

I am currently working on implementing an event bus and have organized all event names and parameters in one interface. Here is how it looks: interface A { a: { x: number y: number } b: { name: string } } function on<T exte ...

Challenges arise with data updating following a mutation in @tanstack/react-query

As I work on building an e-commerce website using React, I have a specific feature where users can add products to their favorites by clicking a button. Following this action, I aim to update the profile request to display the user's information along ...

You cannot assign a type in react-chartjs-2

Currently, I am working on a project using React and TypeScript. However, I have encountered an error related to types in my code. Can someone guide me on how to resolve this issue? The 'position' variable is set as a string data type. For more ...

Issue with lodash-es during compilation: 'Exclude' name not found

I'm encountering a similar issue to the one described in this post (following lodash error on build 'Cannot find name 'Exclude'') ERROR in ... /node_modules/@types/lodash/common/object.d.ts (1689,12): Cannot find name 'Exclud ...

Webpack 2.7.0 throws an error: "Unexpected parameter: theme"

At the moment, I am on webpack 1.16.0 and using --theme as an argument to set the output path and plugin paths. The command appears as: rimraf dist && webpack --bail --progress --profile --theme=<name of theme> However, as I try to upgrade ...

Angular2 and Firebase App unable to Compile due to TypeScript Issue

Latest Update: The recent issue causing the app to crash upon launch has been successfully resolved. Interestingly, it was not due to TypeScript compilation errors. In the Git repository's main.ts file, all that was needed was a simple line change: ...

Creating a personalized menu using Nextron (electron) - Step by step guide

I'm currently in the process of developing an app with Nextron (Electron with Nextjs and Typescript). Although I have the foundation of my Next app set up, I've been encountering issues when attempting to create a custom electron menu bar. Every ...

When Angular encounters :host-context([dir=rtl]) .ion-float-start, it raises a warning about an unmatched pseudo-class in the context of multiple projects within a single angular.json file

I am currently working on an Angular Project that is being used for two different web apps with separate backends. The frontend remains the same for both projects. However, after adding the second project to the angular.json file, I started receiving some ...