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

How to create an event to get the clicked data of the graph #203

Open
ricardohernandez opened this issue Aug 2, 2022 · 5 comments
Open

Comments

@ricardohernandez
Copy link

ricardohernandez commented Aug 2, 2022

chartEvents: {
'click': () => {
const selection = ????
}

in old versions i see that "ref" works like ->this.$refs.gchart.getSelection(), but not works now.
any help?

@Jan-Heussner
Copy link

Jan-Heussner commented Apr 19, 2023

This works for me:
this.$refs.gchart.chartObject.getSelection()

@UptimizeNL
Copy link

Unfortunately this doesn't seem to work (anymore). I'm using Vue3 and version 1.1.0 of vue-google-charts. It's impossible to get the current selection of a chart. chartObject doesn't seem to exist anymore?

@luukvr
Copy link

luukvr commented Nov 6, 2023

Found a workaround for vue 3, if you use the @ready you can receive a proxy to the chartObject

<GChart :data="data" :options="options" :events="chartEvents" @ready="setupChart" type="PieChart" />

chartEvents: { onmouseover: this.setSelection, ready: () => { this.setSelection({ row: 0, column: null }); }, },

setupChart(chartObject) { this.chart = chartObject; }, setSelection(object) { if (object !== null) { this.chart.setSelection([object]); } },

@gregoirepuget
Copy link

I don't know how to use click event with Nuxt 3. If someone can help. Thank you.

@Freekbron
Copy link

Use the select event name:

<template>
  <GChart :events="chartEvents" @ready="(chartWrapper) => (chart = chartWrapper)" />
</template>
<script lang="ts" setup>
const chart = ref();
const chartEvents = {
  select: () => {
    // Get the selected key
    const selectionKey = chart.value.getSelection()[0];
  },
};
</script>

The GoogleVizEvents type seems to be wrong for the events prop. But it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants