Synchronizing charts

Share active observations between independent owners.

Explicit group

Bind the same group to [synchronization] on the charts you want to connect. The group factory belongs to the Web renderer, which the adapter uses as a peer.

linked-charts.ts
import { Component, DestroyRef, inject, input } from '@angular/core';
import { NeuralChart, type ChartData } from '@neural-charts/angular';
import { createChartSyncGroup } from '@neural-charts/web';

@Component({
  selector: 'app-linked-charts',
  imports: [NeuralChart],
  template: `
    <nc-chart [data]="first()" [instanceId]="idPrefix() + '-first'" [synchronization]="group" />
    <nc-chart [data]="second()" [instanceId]="idPrefix() + '-second'" [synchronization]="group" />
  `,
})
export class LinkedCharts {
  readonly first = input.required<ChartData>();
  readonly second = input.required<ChartData>();
  readonly idPrefix = input.required<string>();
  readonly group = createChartSyncGroup();

  constructor() {
    inject(DestroyRef).onDestroy(() => this.group.destroy());
  }
}

End of life

Controllers leave the group when destroyed. The group owner calls synchronization.destroy() when it is no longer needed. An unmatched datum never activates an unrelated observation.