Chart.js& Angular 2-点击事件中的ng2-charts自定义 [英] Chart.js & Angular 2 - ng2-charts Custom on Click Event

查看:69
本文介绍了Chart.js& Angular 2-点击事件中的ng2-charts自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Angular 2项目中实现ng2-charts,我想知道如何创建自定义onclick事件.意思是,我想覆盖购物车上的当前onclick事件以执行一些自定义功能(重定向到页面,显示模式等).

I am trying to implement ng2-charts in my Angular 2 project and I was wondering about creating custom onclick events. Meaning, I want to override the current onclick events on the carts to do some custom functions (redirect to a page, have a modal show up, etc).

有没有简单的方法可以做到这一点?它是内置的吗?

Is there a simple way to do this? Is it built in at all?

任何见识都会受到赞赏

推荐答案

尝试阅读 DOCS

Try to read DOCS

他们对用法有很好的理解,可以理解.

They have pretty good and understandable explanation of use.

内置2个事件处理程序:

There-are built-in 2 event handlers:

事件

chartClick:单击图表时触发,返回有关活动点和标签的信息

chartClick: fires when click on a chart has occurred, returns information regarding active points and labels

chartHover:在图表上进行鼠标移动(悬停)时触发,返回有关活动点和标签的信息

chartHover: fires when mousemove (hover) on a chart has occurred, returns information regarding active points and labels

在代码中看起来像这样:

In code it looks like that:

 <base-chart class="chart"
            [datasets]="lineChartData"
            [labels]="lineChartLabels"
            [options]="lineChartOptions"
            [colors]="lineChartColours"
            [legend]="lineChartLegend"
            [chartType]="lineChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="chartClicked($event)"></base-chart>
  </div>

chartHoveredchartClicked是您的自定义函数,可以使用其他名称,并执行自定义功能,例如显示模式,重定向到url等.

that chartHovered and chartClicked are your custom functions, which could has another names, and do custom things like showing modal, redirect to url etc.

这篇关于Chart.js&amp; Angular 2-点击事件中的ng2-charts自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆