Visualization custom element
Embed a saved visualization with the legacy gd-insight element, set its workspace, locale, title, filters, and size, and subscribe to its events.
gd-insight is the legacy visualization element, kept for existing integrations. For new integrations, use gd-insight-embed, which adds the filters, title, config, and context properties, the refresh() method, and the gd-ready and gd-error events. See Dashboard and visualization embed elements.gd-insight embeds a single saved visualization. It renders the InsightView component:
<!-- minimal setup -->
<gd-insight insight="my-visualization-id"></gd-insight>
gd-insight element uses a flex layout that adjusts to the size of its container. If the container doesn’t have display: flex, the element has zero height. You can also set the height explicitly with CSS, for example with the inline style="height: 500px".Supported attributes
<!-- all supported attributes -->
<gd-insight
insight="my-visualization-id"
workspace="my-workspace-id"
locale="en-US"
title="Custom visualization title"
mapbox="my-mapbox-token"
agGrid="my-ag-grid-license-key"
></gd-insight>
insight- required, the ID of the visualization to embed.workspace- optional, the ID of the workspace of this visualization. By default, it’s taken from the context, for example from the script URL.locale- optional, defaults toen-US. The localization of the visualization UI. Use the hyphenated form (en-US,de-DE); an unknown value falls back toen-US. For all available languages, see the full list of available localizations.title- optional. As a boolean attribute, it renders the title stored with the visualization. As a string, it renders that string instead.filters- optional, a JSON array of filter objects applied to the visualization. An invalid value is logged withconsole.errorand ignored.mapbox- optional, a Mapbox access token used by geo charts. Overrides themapboxTokenfrom the context.agGrid- optional, an AG Grid license key used by pivot tables. Overrides theagGridTokenfrom the context.
<!-- with no `title` attribute, the title isn't rendered -->
<gd-insight insight="my-visualization"></gd-insight>
<!-- with a boolean `title` attribute, the title is loaded from the server and rendered above the visualization -->
<gd-insight insight="my-visualization" title></gd-insight>
<!-- with a string `title` attribute, that string is rendered above the visualization -->
<gd-insight insight="my-visualization" title="My custom title"></gd-insight>
You can also set the workspace ID once on the context instead of passing it to every element. See the code example in Web Components authentication.
Supported events
gd-insight emits the following events. The detail of each event is the argument of the matching InsightView callback:
drill- the user drilled in the visualization. The detail is the drill event,IDrillEvent.error- loading or computing the visualization failed. The detail is theGoodDataSdkError.exportReady- the visualization is ready to be exported. The detail is the export function,IExportFunction; call it to export the data.loadingChanged- the loading state of the visualization changed. The detail isILoadingState.insightLoaded- the visualization definition has loaded. The detail is theIInsight.
Events don’t bubble and aren’t cancelable. Subscribe to them as to any other DOM event:
<gd-insight insight="my-visualization" id="some-dom-id"></gd-insight>
<script>
const insightEl = document.getElementById("some-dom-id");
insightEl.addEventListener("insightLoaded", (event) => {
// See what's in the event payload
console.log(event.detail);
});
</script>
Related
Embed a dashboard or a saved visualization with gd-dashboard-embed and gd-insight-embed, and drive them through properties, methods, and events.
Understand what the Web Components library is, when to choose it over an iframe or the React library, how it loads, and what limits it has.
Authenticate Web Components against GoodData using the auth=sso script parameter for automatic SSO or setContext for a programmatic flow.
Render any saved GoodData visualization by reference with the InsightView component.
Embed a dashboard with gd-dashboard, configure its workspace, locale, and read-only mode, and subscribe to dashboard events.