Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular2 Highcharts:单击自定义图例标题上的事件_Javascript_Angular_Highcharts_Angular2 Highcharts - Fatal编程技术网

Javascript Angular2 Highcharts:单击自定义图例标题上的事件

Javascript Angular2 Highcharts:单击自定义图例标题上的事件,javascript,angular,highcharts,angular2-highcharts,Javascript,Angular,Highcharts,Angular2 Highcharts,下面是我创建的高度图表。我添加了一个自定义的图例标题,它给出了count2000。我正在尝试在此2000上有一个单击事件,但无法添加它 我的图例代码: legend: { useHTML: true, enabled: true, align: 'center', verticalAlign: 'bottom', layout: 've

下面是我创建的高度图表。我添加了一个自定义的图例标题,它给出了count2000。我正在尝试在此2000上有一个单击事件,但无法添加它

我的图例代码:

 legend: {
                useHTML: true,
                enabled: true,
                align: 'center',
                verticalAlign: 'bottom',
                layout: 'vertical',
                x: 0,
              y:30,
                symbolHeight: 12,
                itemMarginBottom: 1,
                symbolWidth: 25,
                symbolRadius: 1,
                labelFormatter: function () {
                    return '<div style="width:180px"><span class="pull-left" style= "font-weight: 500; padding-bottom: 5px">' + this.name +
                    '</span><span class="pull-right" style= "font-weight: 500" >' + this.value +
                    '</span></div> ';
                },
                title: {
            text: ' Issues<br/><span style="font-size: 9px; color: #666; font-weight: normal">Total: 2000</span>' 
            //Click event on 2000 
            // call donut service's get total info. Need not have to pass any variable. 

        },


            }

您可以在图表加载事件上附加onclick事件

 template: `
    <chart  [options]="options" (load)="onChartLoad($event.context)">
    </chart>

示例:

非常感谢,它很有效。对于图例项单击,我正在尝试使用该类。但它只有图表属性,而没有类。因此,我无法使用servicethis.donutservice的局部变量。在LegendTitleClick中,我可以获得服务的局部变量。legendItemClick:function e{console.logthis;return false;}您需要为组件正确设置服务。使用donut服务设置提供程序和正确的构造函数。如果要将其用作hc事件中的组件,则需要将其正确绑定。例如,它真的很有帮助。谢谢这听起来有点疯狂。早上的时候效果很好,但突然,它在控制台中抛出错误,无法读取CompiledTemplate.proxyViewClass.View_DonutComponent0.handleEvent_7/AppModule/DonutComponent/component.ngfactory.js的undefined.at DonutComponent.webpackJsonp.632.DonutComponent.onChartLoad的属性“children”。
onChartLoad(chart) {
  this.chart = chart;
  var t = chart.legend.title.element.children[0].children[1]
  t.onclick = () => this.onLegendTitleClick()
}

onLegendTitleClick() {
  console.log('title clicked', this)
}