VolkovLabs / volkovlabs-dynamictext-panel

Business Text Panel for @grafana
https://docs.volkovlabs.io
Apache License 2.0
78 stars 14 forks source link

Javascript is not working properly #288

Closed iamfaizanrashid closed 3 months ago

iamfaizanrashid commented 3 months ago

in content box ===> working

<div class="custom-pre""> {{{json @root}}}

in css box =====> working

.custom-pre { color: rgb(218, 143, 45); background-color: rgb(46, 50, 51); padding: 10px; overflow: auto; white-space: pre-wrap; }

in javascript box =====> not working

const jsonData = JSON.parse('{{json @root}}'); const filteredData = Object.entries(jsonData) .filter(([key, value]) => value > 0) .map(([key, value]) => "${key}": ${value},) .join('\n');

// Display filtered data in a separate element (optional) const filteredElement = document.createElement('div'); filteredElement.classList.add('custom-pre'); filteredElement.textContent = filteredData.slice(0, -1); // Remove the trailing comma document.body.appendChild(filteredElement);

when we add java script it don't work in dynamic text panel

iamfaizanrashid commented 3 months ago

2024-03-10_16-54

mikhail-vl commented 3 months ago

@iamfaizanrashid {{json @root}} is a Handelbars template. It's not supported in the JavaScript.

If you are using the latest version of the Dynamic Text Panel, you can access your data using context.data. Please take a look at the latest blog for details: https://volkovlabs.io/blog/dynamictext-panel-4.3.0-20240108/