download-csv-js
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
download-csv-js [2022/05/10 11:35] – created emozolyak | download-csv-js [2022/05/12 08:35] – [Button release script] emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Example of graph data download with JS for dashbaord | + | ====== Example of graph data download with JS for dashboard |
+ | |||
+ | The standard method of exporting data from graphs to XLS, HTML, CSV files has the resolution of the selected view on the respective graph, not all data - due to performance issues. | ||
+ | Please refer to the [[access_via_api|API article]] on how to retrieve data with REST requests. | ||
+ | |||
+ | In the following example, dashboards' | ||
+ | |||
+ | ===== Dashboard layout ===== | ||
+ | There are 4 control elements on the dashboard you must provide: | ||
+ | {{ :: | ||
+ | -Start time date picker | ||
+ | -End time date picker | ||
+ | -Button for invoking the JS script | ||
+ | -Dictionary element for selecting one of the many graphs you may have. E.g. if you have graphs with IDs of 1, 2, 3... you have to create a dictionary of 1, 2, 3.... and bind it with the register that will be used for the element on the dashboard. | ||
+ | |||
+ | ===== Script ===== | ||
+ | |||
+ | Put the following script into the ' | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ==== Script text ==== | ||
<code javascript> | <code javascript> | ||
- | const DATA = { | + | const DATA = { // constant names for accessing the dashboard selection |
- | TIME: {START: 7, END: 8}, | + | TIME: {START: 7, END: 8}, // start and end time register ids |
- | | + | |
- | | + | |
- | | + | |
}; | }; | ||
- | const MAX_SLICES = 2999; | + | const MAX_SLICES = 2999; // max number of the slices in the graph data api call |
const TIMEOUT = 5e3; | const TIMEOUT = 5e3; | ||
- | const START_GRAPH_ID = 1; | + | const START_GRAPH_ID = 1; // start number of the range for graphs ids |
- | const END_GRAPH_ID = 2; | + | const END_GRAPH_ID = 2; // end number |
let _i; | let _i; | ||
Line 123: | Line 144: | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ==== Button release script ==== | ||
+ | |||
+ | Because the dashboard expects the register change be greater than 0, we have to reset this register after each use. | ||
+ | The following script can do that: | ||
+ | <code lua> | ||
+ | BUTTON_REG_ID = 9 | ||
+ | |||
+ | function main (userId) | ||
+ | | ||
+ | local cur_value = R(BUTTON_REG_ID) | ||
+ | | ||
+ | if (not resetDemand and cur_value > 0) then | ||
+ | resetDemand = true -- postpone reset for one scan for JS to detect change | ||
+ | return | ||
+ | end | ||
+ | | ||
+ | if (resetDemand) then | ||
+ | reset(BUTTON_REG_ID) | ||
+ | resetDemand = false | ||
+ | end | ||
+ | | ||
+ | end | ||
+ | |||
+ | function reset(reg) | ||
+ | local cur_value = R(reg) | ||
+ | if cur_value and cur_value ~= 0 then | ||
+ | W(reg, 0) | ||
+ | end | ||
+ | end | ||
</ | </ | ||
download-csv-js.txt · Last modified: 2023/10/15 18:07 by emozolyak