TypeScript types for custom Chart.js configurations.
npm i chart.js ng2-charts
File: src/utils/types/custom-chart-configuration.ts
import {
ChartConfiguration,
ChartOptions,
ChartType,
DefaultDataPoint,
} from 'chart.js';
export type VerticalHoverLineOptions = {
color?: string;
};
export type HoverSegmentOptions = {
color?: string;
indexAxis?: 'x' | 'y';
};
type PluginsOf<TType extends ChartType> =
ChartOptions<TType> extends { plugins?: infer P } ? NonNullable<P> : never;
export type CustomPluginOptionsByType<TType extends ChartType> =
PluginsOf<TType> & {
verticalHoverLine?: VerticalHoverLineOptions;
hoverSegment?: HoverSegmentOptions;
};
export type CustomChartOptions<TType extends ChartType = ChartType> = Omit<
ChartOptions<TType>,
'plugins'
> & {
plugins?: CustomPluginOptionsByType<TType>;
};
export type CustomChartConfiguration<
TType extends ChartType = ChartType,
TData = DefaultDataPoint<TType>,
TLabel = unknown,
> = Omit<ChartConfiguration<TType, TData, TLabel>, 'options'> & {
options?: CustomChartOptions<TType>;
};
This module extends Chart.js type definitions to support custom plugins with proper TypeScript typing.
VerticalHoverLineOptions: Configuration for the vertical hover line plugin
color: Optional color string for the hover lineHoverSegmentOptions: Configuration for the hover segment plugin
color: Optional color string for the segment highlightindexAxis: Chart orientation ('x' for vertical, 'y' for horizontal)CustomPluginOptionsByType: Extends Chart.js plugin options with custom plugin configurations
CustomChartOptions: Chart.js options type extended with custom plugin support
CustomChartConfiguration: Complete chart configuration type with custom plugin typing, maintaining full Chart.js type safety
These types ensure proper TypeScript intellisense and type checking when using custom Chart.js plugins.
chart.js: Chart.js type definitionsAngular Material Dev UI (or Angular Material Blocks) is one place stop for developers to explore components and blocks for their Angular Material and Tailwind CSS based applications.
Find us on X (Twitter), LinkedIn, Instagram & Threads