ae3e / ae3e-plotly-panel

Plotly panel for Grafana
Apache License 2.0
94 stars 24 forks source link

Click Script gives error and not updating variables #42

Open KengHzou opened 2 years ago

KengHzou commented 2 years ago

I'm using same dashboard on grafana 7.x and 8.0,

console log showed in picture,

image

image

z0rzi commented 2 years ago

I faced the same issue, and found a solution after poking around in the code:

The function executed when you click gets 3 arguments, as you can see here:

var f = new Function('data', 'getLocationSrv', 'getTemplateSrv', this.props.options.onclick);
f(data, getLocationSrv, getTemplateSrv);

data, getLocationSrv and getTemplateSrv.

And from the Grafana Docs, you can find how to update a variable from the LocationSrv.


So TL;DR, simply use:

getLocationSrv().update({
  query: {
    'var-service': 'billing',
  },
  partial: true,
  replace: true,
});
fifofonix commented 2 years ago

This is a good workaround for user-defined variables but seemingly cannot be used to control the timerange of the main window by updating 'from' and 'to' in the query map, as was possible in Grafana < 8.0 with the windowUpdateVariables option. Does anyone have a solution for updating these?

z0rzi commented 2 years ago

Hum.. Not even with the __from and __to notations? (with the underscores)

fifofonix commented 2 years ago

Apologies. User error. I had inadvertently pinned the time range of a panel. The standard from and to work as expected with this workaround. Thanks again!

kkevvai commented 2 years ago

Hello, Trying to get a minimal example to work but having a hard time ... I'm using Grafana 8.4.6 & Plotly panel 0.5.0. Using the example provided here as a starting point, I'm trying to get the click script to update the 'project' dashboard variable. With the click script that comes with this example panel, the console reports the same error as @KengHzou was seeing. Changing it to (as suggested by @z0rzi)

getLocationSrv().update({
  query: {
    'var-service': 'billing',
  },
  partial: true,
  replace: true,
});

results in another error (Uncaught ReferenceError: getLocationSrv is not defined). image

Any help on how this should be modified would be greatly appreciated!

CliveUnger commented 6 months ago

So as I understand, the window.updateVariables() is deprecated? Therefore the default value that is populated in the click data field should be updated?