Angular
Integrate SVG charts in a standalone component and control their state with signals.
Installation
Start in the root of an Angular 22.2.3 or compatible application.
npm install @neural-charts/angularnpm resolves the Web renderer as a peer, and Web installs Core. The adapter shares @angular/core and @angular/common with your application.
First chart
Create src/app/weekly-chart.ts. Then import WeeklyChart in the view where you want it. The example places it in the root component.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { NeuralChart, type ChartData, type ChartOptions } from '@neural-charts/angular';
@Component({
selector: 'app-weekly-chart',
imports: [NeuralChart],
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<nc-chart [data]="data()" [options]="options()" instanceId="weekly-visits" (pointActivate)="lastPoint.set($event.id.pointId)" />'
})
export class WeeklyChart {
readonly data = signal<ChartData>({
"type": "line",
"axes": {
"x": {
"type": "linear"
},
"y": {
"type": "linear",
"includeZero": true
}
},
"series": [
{
"id": "visits",
"name": "Visits",
"data": [
{
"id": "mon",
"x": 1,
"y": 12
},
{
"id": "tue",
"x": 2,
"y": 18
},
{
"id": "wed",
"x": 3,
"y": 15
}
]
}
]
});
readonly options = signal<ChartOptions>({
"title": "Weekly activity",
"locale": "en",
"height": 360,
"tooltip": {
"enabled": true,
"crosshair": true
}
});
readonly lastPoint = signal<string | null>(null);
}import { Component } from '@angular/core';
import { WeeklyChart } from './weekly-chart';
@Component({
selector: 'app-root',
imports: [WeeklyChart],
template: '<app-weekly-chart />'
})
export class App {}Run the server from the root and open the address printed in your terminal to see the chart.
npx ng serveData, state and events
Replace data or options immutably. Bind pointActivate, selectionChange, hiddenSeriesChange, viewportChange or diagnostic as needed. When you control state, apply proposals by updating options.
import { ChangeDetectionStrategy, Component, input, signal } from '@angular/core';
import { NeuralChart, type ChartData, type ChartOptions } from '@neural-charts/angular';
@Component({
selector: 'app-controlled-chart',
imports: [NeuralChart],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<nc-chart [data]="data()" [options]="options()" instanceId="controlled-visits"
(hiddenSeriesChange)="applyVisibility($event)"
(pointActivate)="lastPoint.set($event.id.pointId)" />
<p>{{ lastPoint() }}</p>
`,
})
export class ControlledChart {
readonly data = input.required<ChartData>();
readonly options = signal<ChartOptions>({ hiddenSeriesIds: [] });
readonly lastPoint = signal<string | null>(null);
applyVisibility(hiddenSeriesIds: readonly string[]): void {
this.options.update(applied => ({ ...applied, hiddenSeriesIds }));
}
}Customization and export
Project typed templates for the title, tooltip, legend and labels. Use viewChild to export the applied chart from the component.
import { Component, input } from '@angular/core';
import {
NeuralChart, NeuralChartTooltipTemplate, type ChartData, type ChartOptions,
} from '@neural-charts/angular';
@Component({
selector: 'app-chart-with-tooltip',
imports: [NeuralChart, NeuralChartTooltipTemplate],
template: `
<nc-chart [data]="data()" [options]="options" instanceId="tooltip-example">
<ng-template ncChartTooltip let-tip><strong>{{ tip.text }}</strong></ng-template>
</nc-chart>
`,
})
export class ChartWithTooltip {
readonly data = input.required<ChartData>();
readonly options: ChartOptions = { tooltip: { enabled: true } };
}Lifecycle and testing
Keep a stable, unique instanceId for SSR. Angular destroys the owner when the component is removed. Test inputs and outputs with TestBed, and verify hydration and navigation in a real browser.
Server rendering guide