Transform Chart Data Action (Deprecated)
The action module for this action is vb/action/builtin/transformChartDataAction
. The transformChartDataAction is deprecated. Data should be set directly on the chart instead.
Transforms a JSON array with a particular structure into a JSON object containing (array) properties that JET chart component expects.
Page Authors can use this action to take the response from a REST action, turn into a format that this action expects, and use the result returned by this action to assign to a variable bound to the chart component.
The action supports the following parameter.
Parameter Name | Type | Description | Example |
---|---|---|---|
source | Array<Object> | An array of objects, or data points, where each data
point has one of the two structures below. The first is used with charts
that show groups of data for one or more series, such as bar and pie.
The second is used with charts that show three dimensions of data, such
as
bubble.
|
|
The action returns a JSON object with the following properties.
Return Type | Description | Example |
---|---|---|
Object | The Object has two properties. The properties differ
based on the structure that's passed in.
|
|
The example below shows a chain called "fetchTechnicianStatsChain" with four actions chained together to take a REST response and turn the JSON response into a form that can be used by a Chart UI component. The four actions are:
-
Use a Call REST endpoint action to fetch technician stats.
-
Use an Assign Variables action to map the response from (1) to a form that the Transform Chart Data action expects. If the REST response is so deeply nested that a simple transformation of source to target using an Assign Variables action is not possible, page authors can use a page function (using a Call Function action) to transform the data into a form that the Transform Chart Data action expects.
-
Use a Transform Chart Data action to take the response from (2) and turn it into a form that a Chart component can consume.
-
Use an Assign Variables action to store the return value from (3) in a page variable.
"actions": { "fetchTechnicianStatsChain": { "variables": { "flattenedArray": { "type": [ { "group": "string", "series": "string", "value": "string" } ], "description": "array of data points", "input": "none" } }, "root": "fetchTechnicianStats", "actions": { "fetchTechnicianStats": { // (1) "module": "vb/action/builtin/restAction", "parameters": { "endpoint": "ifixitfast-service/getTechnicianStats", "uriParams": { "technician": "{{ $page.variables.technician }}" } }, "outcomes": { "success": "flattenDataForBar" } }, "flattenDataForBar": { // (2) "module": "vb/action/builtin/assignVariablesAction", "parameters": { "$chain.variables.flattenedArray": { "source": "{{ $chain.results.fetchTechnicianStats.body.metrics }}", "reset": "toDefault", "mapping": { "$target.group": "$source.technician", "$target.series": "$source.month", "$target.value": "$source.incidentCount" } } }, "outcomes": { "success": "transformToBarChartData" } }, "transformToBarChartData": { // (3) "module": "vb/action/builtin/transformChartDataAction", "parameters": { "source": "{{ $chain.variables.flattenedArray }}" }, "outcomes": { "success": "assignToPageVariable" } }, "assignToPageVariable": { // (4) "module": "vb/action/builtin/assignVariablesAction", "parameters": { "$page.variables.incidentChartDS": { "source": "{{ $chain.results.transformToBarChartData }}", "reset": "toDefault" } } } } } }