getDefaultColors
Reference
getDefaultColors(themeColor)returns the default series colors that the standard Bar and Line charts use.- Use it for a custom chart so the series colors match the standard charts. The first color is the one you pass in; the rest are a fixed list.
Parameters
themeColor- Type:
string - Description: A color value used as the first series color, usually taken from the tenant theme (see useTheme and the color palette).
- Type:
Returns
string[] — the list of colors. Use the index of the series to pick its color.
Usage Example
function Example({ series }) {
const { protrakComponents } = React.useContext(customWidgetContext);
const { useTheme, getDefaultColors, LineChartRenderer } = protrakComponents;
const theme = useTheme();
const colors = React.useMemo(
() => getDefaultColors(theme.colorPalette.SECONDARY_DARK),
[theme]
);
const traces = series.map((s, index) => ({
name: s.name,
x: s.x,
y: s.y,
line: { color: colors[index % colors.length] },
marker: { color: colors[index % colors.length] },
}));
return <LineChartRenderer data={traces} mode="lines+markers" />;
}