angular - 如何使用角度组件调用 Apexcharts 事件中的函数?
问题描述
我正在使用 apexcharts 角度库来图形表示我的数据。当我单击该栏时,我想触发另一个功能。这是我对条形图的配置。
this.chartOptions = {
series: [
{
name: "basic",
data:[25,30,35,40]
}
],
chart: {
type: "bar",
height: 350,
events: {
click(event, chartContext, config) {
console.log(config.seriesIndex);
console.log(config.dataPointIndex);
//this.getStates(config.dataPointIndex);
var test: number = config.dataPointIndex;
console.log(config.globals.labels[test]);
this.getStates(test);
}
}
},
plotOptions: {
bar: {
horizontal: true
}
},
dataLabels: {
enabled: false
},
xaxis: {
categories: ["India","Pakistan","USA","England"]
}
}
在这里,getStates 是我想要在单击图表中的任何条时触发的函数。
有人可以回复如何调用该功能吗?
解决方案
您可以传入箭头函数作为回调来保留this
关键字的含义。
chart: {
type: "bar",
height: 350,
events: {
click: (event: any, chartContext: any, config: any) => {
this.getStates(config.dataPointIndex);
console.log(config.seriesIndex);
console.log(config.dataPointIndex);
var test: number = config.dataPointIndex;
console.log(config.globals.labels[test]);
this.getStates(test);
}
}
}
您可以在此处this
找到有关回调中关键字含义的更多信息。
推荐阅读
- python - 搜索特定单词并移动 pdf
- python - 多列的itertools组合
- java - 使用 Javers 为审核组添加评论
- javascript - 根据地址栏 URL 更改按钮 HREF
- c# - DotNetFiddle 和 Console.ReadLine 出现问题,在按下 ENTER 键时会导致重新运行
- python - Discord.py 机器人,当用户添加反应时分配角色
- reactjs - 一秒钟后反应组件在heroku上消失
- android - Flutter 在 ListView 返回类型 String 中显示嵌套 json 不是“Map”类型的子类型
' 在类型转换中 - saml-2.0 - 使用 Microsoft AD SAML 创建 Web 应用程序
- akka.net - 当 CPU 处于高压状态时,Akka.NET 具有持久性丢弃消息?