react-google-charts icon indicating copy to clipboard operation
react-google-charts copied to clipboard

Example of listening to the controlWrapper events (i.e. statechange event of chartRangeFilter)

Open PoornakumarRasiraju opened this issue 5 years ago • 3 comments

@rakannimer could you provide an example for how to listen to the statechange event of controlWrapper (ChartRangeFilter)?

https://github.com/rakannimer/react-google-charts/issues/263 callback function doesn't have the controlWrapper to attach events. Planning to achieve below:

google.visualization.events.addListener(controlWrapper, 'statechange', eventArgs => {

});

PoornakumarRasiraju avatar May 19 '20 21:05 PoornakumarRasiraju

You can listen to changes in controlWrapper using controlEvents inside controls. e.g.:

<Chart
  chartType={chartType}
  data={data}
  options={chartOptions}
  chartPackages={["corechart", "controls"]}
  controls={[
    {
      controlEvents: [
        {
          eventName: "statechange",
          callback: ({ controlWrapper }) => {
            console.log(controlWrapper.getState());
          },
        },
      ],
      controlType: "ChartRangeFilter",
      options: {
        filterColumnIndex: 0,
        ui: {
          chartType: "LineChart",
          chartOptions: {
            chartArea: { width: "100%", height: "70%" },
            hAxis: { baselineColor: "none" },
          },
        },
      },
      controlPosition: "bottom",
      controlWrapperParams: {
        state: {
          range: {
            start: startDate,
            end: endDate,
          },
        },
      },
    },
  ]}
/>;

osamasayed avatar Oct 20 '20 22:10 osamasayed

But if we want to get the state inside the callback ...the controlwrapper refuse to move

Kader198 avatar Dec 31 '20 13:12 Kader198

But if we want to get the state inside the callback ...the controlwrapper refuse to move

how did you solve this?

amankumarm avatar Dec 15 '22 10:12 amankumarm