InsightView
Render any saved GoodData visualization by reference with the InsightView component.
The InsightView component is a generic component that renders visualizations created and saved in Analyze.
You pass a reference to the saved visualization in the insight prop: an identifier string, or an ObjRef created with idRef. GoodData Cloud and GoodData.CN reference objects by identifier. InsightView loads the definition from the workspace, so the buckets, filters, and properties come from the saved visualization. Use the individual chart components, such as Treemap, when you define the buckets in your code instead.
How it works
InsightViewloads the saved visualization together with the workspace color palette, the user workspace settings, and the permissions of the current user.- Unless
executeByReferenceis set, it adds the filters from thefiltersprop to the visualization’s own filters. - It reads the visualization type from the saved visualization and renders the matching visualization.
| Type | Renders as |
|---|---|
area, bar, bubble, bullet, column, combo, combo2, dependencywheel, donut, funnel, heatmap, line, mekko, pie, pyramid, radar, sankey, scatter, treemap, waterfall | The chart of that type. combo is the older combo chart. |
headline | Headline |
table | Pivot table. The new pivot table is used unless the workspace setting enableNewPivotTable is false. |
pushpin | Geo pushpin chart. The new MapLibre-based implementation is used when the workspace setting enableNewGeoPushpin is true, which is the default on GoodData Cloud and GoodData.CN. With false, the legacy Mapbox-based chart renders, and it needs a Mapbox token. |
choropleth | Geo area chart |
repeater | Repeater |
xirr | XIRR |
The saved types tablenext and pushpinnext render the new pivot table and the new geo pushpin chart directly. For any other type, InsightView logs a warning to the console and shows the default error component with the “unknown visualization” message.
Loading and errors
| Situation | What shows | Callbacks |
|---|---|---|
| The visualization, color palette, settings, or permissions are loading | LoadingComponent (default: LoadingComponent from @gooddata/sdk-ui). The visualization area has zero height meanwhile. | None. onLoadingChanged doesn’t fire for this phase. |
| The visualization is loaded | LoadingComponent | onInsightLoaded receives the saved visualization. It fires when a visualization with a different reference loads. It doesn’t fire again when only filters change, but it does fire again after InsightView remounts. |
| The visualization loads or executes its data | LoadingComponent | onLoadingChanged with { isLoading: true }, then { isLoading: false } |
| The visualization is rendered | The visualization | onDataView, onExportReady, and pushData when the visualization calls them |
| Loading the visualization or the permissions fails | ErrorComponent (default: ErrorComponent from @gooddata/sdk-ui) | onError. A load that a newer load replaced doesn’t call it. |
| Loading the color palette or the settings fails | ErrorComponent | None |
| The visualization fails to render or execute | ErrorComponent | onError, then onLoadingChanged with { isLoading: false } |
- The error component shows only when none of the visualization, color palette, settings, or permissions is still loading. Errors with a known error code get a localized message and description. Errors that aren’t GoodData.UI SDK errors show the generic unknown-error message. SDK errors with no mapped code show the error code as the message.
- A visualization error is cleared as soon as the visualization starts loading again.
- The function passed to
onExportReadyuses the saved visualization’s title as the export title when you don’t settitlein the export config. - You can replace
onDrill,onError,onLoadingChanged,onExportReady,onDataView, andpushDatabetween renders. The visualization always calls the latest one. ReplacingonInsightLoadedloads the visualization again.
When it reloads
Reloading compares props by reference. Recreating the rendered visualization compares values.
| Change | Effect |
|---|---|
insight, filters, executeByReference, or onInsightLoaded | Loads the visualization again and shows the loading component. |
backend or workspace | Also loads the color palette, settings, and permissions again. A change of executeByReference also loads the permissions again. |
The loaded visualization (apart from its properties), filters, the workspace settings, or workspace | Recreates the rendered visualization. |
config, drillableItems, colorPalette, execConfig, or the visualization’s properties only | Updates the rendered visualization in place. |
- Switching
localeto a language the component hasn’t loaded yet renders nothing until the translations load. After that,InsightViewmounts again and loads everything again. - Keep
insight(when it is anObjRef),filters, andonInsightLoadedreferentially stable, for example withuseMemoanduseCallback. A new reference, array, or function on every render loads the visualization again on every render. - When a new load starts before the previous one finishes, the previous result is ignored. The request itself is not canceled.
- The loaded visualization definition, color palette, settings, and permissions are cached per workspace, so a reload doesn’t always reach the backend. The cache keeps up to 20 visualizations per workspace for up to 5 workspaces. After you edit a saved visualization, call
clearInsightViewCacheForInsight(workspace, ref)so that the next load (for example after a remount) fetches the new definition. Pass the same kind of reference that you pass toinsight. See Caching.
Configuration
| Prop | What it does |
|---|---|
config | Options for the visualization type, merged with the saved visualization’s properties. For charts, top-level keys in config replace the saved values, so an object such as legend replaces the saved legend object as a whole. A few chart types adjust some keys afterwards; for example, pie and donut charts set chart themselves. The prop is typed loosely, so TypeScript doesn’t check the options against the visualization type. |
filters | Merged with the saved visualization’s filters: attribute filters are combined; a date filter on the same date dataset or a measure value filter on the same measure replaces the saved one. Without executeByReference, the merge happens in the browser. With it, the backend merges them. See Filters. |
executeByReference | Asks the backend to compute the saved visualization by reference instead of sending the full execution definition. Use it only when the backend requires it. |
drillableItems | Which parts of the visualization can be clicked. Clicks call onDrill. |
colorPalette | Replaces the workspace color palette. Without it, the palette comes from the workspace styling settings. |
locale | Locale for texts in the visualization. Without it, the locale comes from the user workspace settings. If that isn’t a valid locale either, en-US is used. Values coming from the data aren’t localized. |
showTitle | true shows the saved visualization’s title after loading. A string shows that string, also while loading. A function receives the loaded visualization and returns the title. |
TitleComponent | Renders the title. It receives title. The default truncates the title to two lines. |
execConfig | Execution settings passed to the visualization’s execution. |
config.mapboxToken and config.agGridToken fall back to MapboxTokenProvider (legacy Mapbox-based geo charts only) / AgGridTokenProvider, then to the workspace settings of the same names. config.maxZoomLevel falls back to the workspace setting.
Limits
InsightViewneeds a backend and a workspace, either in thebackendandworkspaceprops or fromBackendProviderandWorkspaceProvider. There is no explicit check. Rendering without a backend fails with a runtime error instead of showing the error component.- For an unknown visualization type, the default error component shows, not your
ErrorComponent, andonErrorisn’t called. - With
@gooddata/sdk-ui-ext/styles/css/main.cssimported,InsightViewtakes the full height of its parent. Give the parent element an explicit height, as in the examples below.
Filters
To learn how to build the filters that you pass in the filters prop, see Apply filters to visualizations.
Caching
To render a visualization, InsightView needs more than the visualization itself: the workspace color palette, the current user’s workspace settings (including feature flags), and the user’s permissions in the workspace. To avoid repeated requests, InsightView caches this information together with the loaded visualization definitions. The cache is shared by all InsightView components in the application and is kept per workspace: up to 20 visualization definitions for each workspace, for up to 5 workspaces. A cached value is used until you clear it, even when the saved visualization changes on the backend.
To drop the cached definition of one visualization, for example after you edit it, call clearInsightViewCacheForInsight. Pass the same kind of reference that you pass to insight. The new definition is fetched the next time an InsightView loads that visualization, for example after it remounts.
To clear the cached visualization definitions, color palettes, and workspace settings at once, for example after logging out or when switching workspaces, call clearInsightViewCaches. It doesn’t clear the cached user permissions.
import { clearInsightViewCaches, clearInsightViewCacheForInsight } from "@gooddata/sdk-ui-ext";
import { idRef } from "@gooddata/sdk-model";
clearInsightViewCacheForInsight("<workspace-id>", idRef("<visualization-id>"));
clearInsightViewCaches();
Structure
import "@gooddata/sdk-ui-ext/styles/css/main.css";
import { InsightView } from "@gooddata/sdk-ui-ext";
<div style={{ height: 400, width: 600 }}>
<InsightView
insight="<visualization-id>"
config={<chart-config>}
/>
</div>
import "@gooddata/sdk-ui-ext/styles/css/main.css";
import { InsightView } from "@gooddata/sdk-ui-ext";
import { idRef } from "@gooddata/sdk-model";
<div style={{ height: 400, width: 600 }}>
<InsightView
insight={idRef("<visualization-id>", "insight")}
config={<chart-config>}
/>
</div>
The options in config are different for each visualization type. InsightView expects the same configuration type as the matching React component.
Example
import "@gooddata/sdk-ui-ext/styles/css/main.css";
import { InsightView } from "@gooddata/sdk-ui-ext";
<div style={{ height: 400, width: 600 }}>
<InsightView
insight="<visualization-id>"
config={{
colors: ["rgb(195, 49, 73)", "rgb(168, 194, 86)"],
legend: {
enabled: true,
position: "bottom"
}
}}
/>
</div>
Props
| Prop | Type | Required | Description | Inherited from |
|---|---|---|---|---|
insight | ObjRef | string | Yes | Reference to the insight to render. This can be specified by either object reference using URI or using identifier. For convenience it is also possible to specify just the identifier of the insight. | — |
backend | IAnalyticalBackend | No | Backend to work with. Note: the backend must come either from this property or from BackendContext. If you do not specify backend here, then the executor MUST be rendered within an existing BackendContext. | — |
colorPalette | IColorPalette | No | Configure color palette to use for the chart. If you do not specify this, then the palette will be obtained from style settings stored on the backend. | — |
config | IChartConfig | IGeoConfig | IPivotTableConfig | PivotTableNextConfig | any | No | When embedding insight rendered by a chart, you can specify extra options to merge with existing options saved for the insight. | — |
drillableItems | ExplicitDrill[] | No | Configure chart drillability; e.g. which parts of the charts can be clicked. | — |
ErrorComponent | ComponentType<IErrorProps> | No | Component to render if embedding fails. | — |
execConfig | IExecutionConfig | No | execConfig will provide the execution with necessary settings before initiating execution. | — |
executeByReference | boolean | No | Indicates that the execution to obtain the data for the insight should be an ’execution by reference’. Execution by reference means that the InsightView will ask analytical backend to compute results for an insight which is stored on the backend by specifying link to the insight, additional filters and description how to organize the data. Otherwise, a freeform execution is done, in which the InsightView will send to backend the full execution definition of what to compute. This distinction is in place because some backends MAY want to prohibit users from doing freeform executions and only allow computing data for set of insights created by admins. Note: the need for execute by reference is rare. You will typically be notified by the solution admin to use this mode. | — |
filters | IFilter[] | No | Additional filters to apply on top of the insight. | — |
LoadingComponent | ComponentType<ILoadingProps> | No | Component to render while the insight is loading. | — |
locale | ILocale | No | Locale to use for localization of texts appearing in the chart. Note: text values coming from the data itself are not localized. | — |
onInsightLoaded | (insight: IInsight) => void | No | Called when the insight is loaded. This is to allow the embedding code to read the insight data. | — |
showTitle | boolean | string | ((insight: IInsight) => string | undefined) | No | In case this property is boolean it indicates that the title component will be rendered if specified in components properties. In case the property is string, this string must not be empty and will be shown as insight title. In case the property is a function, it should be implemented to take the loaded insight object and return modified title in string representation. | — |
TitleComponent | ComponentType<IInsightTitleProps> | No | Component to render insight title. | — |
workspace | string | No | Workspace where the insight exists. Note: the workspace must come either from this property or from WorkspaceContext. If you do not specify workspace here, then the executor MUST be rendered within an existing WorkspaceContext. | — |
onDataView | OnDataView | No | (Alpha) Called when the visualization loads a DataView, i.e. it receives data from the backend. | IVisualizationCallbacks |
onDrill | OnFiredDrillEvent | No | Called when user triggers a drill on a visualization. | IVisualizationCallbacks |
onError | OnError | No | Called when an error occurs while loading data for the visualization. | IVisualizationCallbacks |
onExportReady | OnExportReady | No | Called when the visualization is ready to be exported. | IVisualizationCallbacks |
onLoadingChanged | OnLoadingChanged | No | Called when loading status of the visualization changes - vis starts or stops loading | IVisualizationCallbacks |
Related
Render a visualization saved in Analyze with InsightView by getting its identifier, importing the component and styles, and setting its insight prop.
Configure drillableItems with header predicates to make visualization measures or attributes interactive and receive drill event context.
Configure chart appearance, axes, legends, colors, and data labels.
Embed a saved visualization with the legacy gd-insight element, set its workspace, locale, title, filters, and size, and subscribe to its events.
Load a saved visualization by reference and return its execution result as a DataViewFacade with optional filters and sorting.