Skip to main content

ShareChartConfig

Import

import {
TimeseriesChartConfig,
CategoricalBarChartConfig,
SingleValueConfig,
PieChartConfig,
DonutChartConfig,
MeterBarChartConfig,
MultiMeterBarChartConfig,
HoneycombChartConfig,
} from '@dynatrace/strato-components-preview/charts';

Use cases

Multiple chart configuration

In certain situations, it may be beneficial to share a common chart configuration across multiple charts of the same type. To avoid the need for repeating the same configuration in each instance, all charts provide a config provider that can be utilized. This provider accepts an object, where the keys are either props of the chart component or the corresponding object representation of each of the chart subcomponent props (e.g. TimeseriesChart.Legend, CategoricalBarChart.ValueAxis, PieChart.Legend, etc.).

ℹ️️ Please note that the config set using this provider has a lower priority than the specific configuration of each chart. This means that if a chart has a specific config, it will override the corresponding property from the provider config.

CodeSandbox

Export chart config

A chart's configuration can be exported at any time for various purposes, such as sharing the configuration with other applications through an intent. The current configuration can be retrieved by creating and assigning a ref to the corresponding ref property of the chart, and then calling ref.getConfig() method.

ℹ️️ When the "getConfig" method is invoked, a snapshot of the serialized configuration is returned. As such, it will not change if the chart's configuration is subsequently modified. It is recommended to ensure that all configurations have been applied to the chart before calling this method

CodeSandbox

Import chart config

The configuration provider for each chart also accepts a string as an input for importing a serialized configuration. When a string is provided, it is internally parsed and applied as the chart configuration.

ℹ️️ Please note that if the configuration provided does not match the properties of the chart configuration, any unknown properties will be ignored. Additionally, if required properties are not provided, or the given config is invalid, default values will be applied.

ℹ️️ It is important to note that due to potential version mismatches in chart packages used in different applications, importing a configuration from another application may not result in a perfect match.

CodeSandbox
Still have questions?
Find answers in the Dynatrace Community