要获取折线图中选中系列的事件,您可以使用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命令来安装它。
希望这可以帮助到您!