Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching click event in line graph(ngx-echarts)

Tags:

echarts

I am using echarts Angular version- ngx-echarts in my project. I want to catch click event done on a line graph. chartClick or any of the mouse event of ngx-echarts library is not working for line graphs but they are working for barGraphs. How can I catch click events in line graph using ngx-echarts

<div echarts [options]="chartOption" 
    (chartClick)="onChartEvent($event, 'chartClick')">
</div>

onChartEvent(event: any, type: string) {
    console.log('chart event:', type, event);
}

Logical entity is not entering the onChartEvent function even when click is performed

like image 308
Anisha Avatar asked Oct 19 '25 09:10

Anisha


2 Answers

In the line chart the 'chartClick' event gets fired only if you click on the points of the lines.

like image 189
retrobitguy Avatar answered Oct 22 '25 05:10

retrobitguy


You can do it by this way. when you build your options, in series object populate:

series: [
                { // your bar
                    type: 'bar',
                    barWidth: '30%',
                    data: myData
                },
                { // shadow bar
                    type: 'bar',
                    barWidth: '30%',
                    itemStyle: {
                        // transparent bar
                        normal: { color: 'rgba(0, 0, 0, 0)' }
                    },
                    barGap: '-100%',
                    data: myDataShadow,
                    animation: false
                }
]

Where myDataShow is a copy of myData.

I recommend you put the biggest value in all positions of myDataShadow to make all bar clickable.

like image 23
Felipe Santana Avatar answered Oct 22 '25 03:10

Felipe Santana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!