Local data instances for multiple data visualizations
A special Data Visualization API data resource is available to fetch data for multiple data visualizations simultaneously. This data resource reduces the number of API calls and thus can speed up data fetching.
When to use
- Multiple data visualizations of the same type have the same data source. For example, you have five visualizations where the visualization type is Single Score and the data source is the Incident [incident] table with the filter
active=true. If you have several groups of indicators with the same type and data source, you can create an instance of the same multiple visualization data resource for each group. - A data visualization has multiple data resources that reference the same data source. For example, you have a Line visualization with a data resource from the "Number of open incidents" indicator and another data resource from the "Average age of open incidents" indicator. Both of these indicators use the Incident.Open data source. For efficiency, you can convert this visualization to use only one data resource.
When not to use
- There is only one data visualization on the UI Builder page.
- The data visualizations on the page are likely to take a long time to load data. In that case, it's better to keep the data loading split between separate data resources.
Set up a multiple visualization data resource
If your use case meets the criteria for a multiple visualization data resource, you can follow this procedure.
Before you begin
Review the use case for a single data resource for multiple visualizations in Local data instances for multiple data visualizations.
Role required: ui_builder_admin, admin
About this task
Procedure
Data resource for three Single score visualizations with the same data source
In this example, we start with a UIB page that contains three Data Visualization components. These components all are of the Single Score visualization type, and all use the same data source.
You follow the general procedure through Step 6. Now you have a Data Visualization API for multiple data visualizations on your Dashboards page.
[
{
"details": {
"visualizationId": "vis_1",
"followFilter": true
},
"configurations": {
"dataConfigurations": [
{
"sourceType": "table",
"dataCategory": "simple",
"order": 0,
"tableOrViewName": "incident",
"aggregateFunction": "COUNT"
}
]
}
},
{
"details": {
"visualizationId": "vis_2",
"followFilter": true
},
"configurations": {
"dataConfigurations": [
{
"sourceType": "table",
"dataCategory": "simple",
"order": 0,
"tableOrViewName": "incident",
"aggregateFunction": "AVG",
"aggregateField": "business_duration"
}
]
}
},
{
"details": {
"visualizationId": "vis_3",
"followFilter": true
},
"configurations": {
"dataConfigurations": [
{
"sourceType": "table",
"dataCategory": "simple",
"order": 0,
"tableOrViewName": "incident",
"aggregateFunction": "AVG",
"aggregateField": "priority"
}
]
}
}
]The request is an array of objects, one for each data visualization. Each visualization has a details property with an arbitrary value for the visualizationId and a boolean followFilter setting whether the visualization follows filter components on the page. In this case, all three visualizations follow filters.
Each visualization also has a configurations property, containing only a dataConfigurations array. Because all the visualizations are of the same type, Single Score, and this visualization type shows only a simple value, all three dataCategory properties are "simple." Similarly, all the visualizations use the same data source. Because the data source is the Incident [incident] table, all three visualizations have a sourceType of "table" and a tableOrViewName of "incident." The only place where the visualizations can vary is in the aggregates they use. Here you see the first one uses a COUNT aggregation, the second takes an AVG aggregate on the business_duration field, and the third takes an AVG of the priority field.
vizId value in the
script for that visualization.function evaluateProperty({api, helpers}) {
const data = api.data.data_visualization_api_for_multiple_data_visualizations_1.output;
if (!data) {
return [];
}
const vizId = 'vis_1';
const dataForViz = data.result.find(d => d.details.visualizationId === vizId);
return dataForViz.dataResponses;
}Request JSON for an indicator
[
{
"details": {
"visualizationId": "vis1",
"followFilter": true
},
"configurations": {
"dataConfigurations": [
{
"sortBy": "choice",
"sortOrder": "asc",
"sourceType": "indicator",
"dataCategory": "trend",
"order": 0,
"splitView": false,
"numberOfGroups": 2,
"uuid": {
"indicator": "fb007202d7130100b96d45a3ce6103b4",
"breakdowns": []
},
"trendBy": "anything",
"trendInterval": "date",
"groupBy": [
"0df47e02d7130100b96d45a3ce610399"
],
"removeMissingIntervalData": false
}
]
}
}
]The first and obvious differences are that the sourceType is "indicator" and the dataCategory is "trend." You also see that instead of a tableOrViewName property, you have a uuid object with the uuid of the Number of open incidents indicator and an empty array that could hold the uuid's of breakdowns for filtering that indicator. Because this visualization supports group-by values, you have a groupBy array that in this case contains only the uuid of the Priority breakdown. Having a group-by implies sorting, and here you see that the sortBy is "choice," reflecting the data type of the Priority breakdown, and the sortOrder is ascending.