...
Data transformation is available only for advanced chart gadget.
Using data transformation
In data transformation you write custom javascript function (or lambda). This functions accepts only one parameter which is an array of rows. Each row has properties with names corresponding to a selected data columns names.
Code Block |
---|
// example of a function
function addAdditionalDimension(data) {
return data.map(row => {...row, newDimension: row.columnA + row.columnB})
} |
Code Block |
---|
// example of a lambda
data => data.map(row => {...row, newDimension: row.columnA + row.columnB}) |
Code Block |
---|
// another example of injecting additional row
function addMissingRow(data) {
const missingRow = {...};
data.push(missingRow);
return data;
} |
Example usage of data transformation
...
Go to Smart QL → New query and place following query
Code Block language sql SELECT floor(created to day) creationday, max(CHAR_LENGTH(body)) maxcommentlength, avg(CHAR_LENGTH(body)) avgcommentlength, min(CHAR_LENGTH(body)) mincommentlength FROM CORE.comments GROUP BY floor(created to day)
Save a query as EXAMPLE_VIEW
Now you will have an example view as shown below:
...
Lets create new plot.
...
Add new gadget to the dashbpard. Choose Smart QL Advanced Gadget. Select newly created EXAMPLE_VIEW as a data feed.
In configuration place following JSON snippet.
Code Block language json { "type": "line", "x": "X", "y": "Y", "color":"C", "plugins": [ { "name": "tooltip" }, { "name": "legend" }, { "name": "export-to" } ] }
In data transformation place following javascript lambda transformation.
Code Block language js data => data.reduce((acc, curr)=>[ ...acc, {X: curr.creationday, Y: curr.maxcommentlength, C: 'max'}, {X: curr.creationday, Y: curr.mincommentlength, C: 'min'}, {X: curr.creationday, Y: curr.avgcommentlength, C: 'avg'} ], [])
Now you will see following plot consisting of 3 data series.
...