要获取折线图中选中系列的事件,您可以使用Syncfusion Angular图表组件的seriesSelection
事件。以下是一个代码示例,演示如何获取折线图中选中系列的事件:
ejs-chart
元素,并设置seriesSelection
事件绑定:
onSeriesSelection
方法来处理选中系列的事件:import { Component, ViewChild } from '@angular/core';
import { ChartComponent } from '@syncfusion/ej2-angular-charts';
@Component({
selector: 'app-chart',
template: `
`,
})
export class ChartComponent {
@ViewChild('chart')
public chart: ChartComponent;
public onSeriesSelection(event: any): void {
// 获取选中的系列
const selectedSeries = event.selectedData;
console.log(selectedSeries);
// 获取选中系列的索引
const selectedSeriesIndex = event.seriesIndex;
console.log(selectedSeriesIndex);
// 获取选中系列的数据点索引
const selectedDataPointIndex = event.pointIndex;
console.log(selectedDataPointIndex);
}
}
在onSeriesSelection
方法中,您可以通过event.selectedData
获取选中的系列,event.seriesIndex
获取选中系列的索引,以及event.pointIndex
获取选中系列的数据点索引。
请注意,您需要先在您的项目中安装@syncfusion/ej2-angular-charts
包,以使用Syncfusion Angular图表组件。您可以在package.json
文件中添加依赖项并运行npm install
命令来安装它。
希望这可以帮助到您!