eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Getting point.dataLabel undefined at times

Hi
need help m getting point.dataLabel undefined sometimes in the below with respect to gantt highchart in angular:


const point = this.point as any;
const text = point.name;
console.log(point)
let textWidth = (this.point as any).dataLabel ? (this.point as any).dataLabel.bBox.width :0;
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

Hello,

Maybe you got that error because there is no dataLabel on that particular point? Try to check first if (point.dataLabel) exists without using the optional chaining.

If this won't help you, then unfortunately that's all I can do without looking at your code. If you need further assistance with this case, please prepare a working demo in an online editor so that I can take a look at it and debug it.

Regards!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Getting point.dataLabel undefined at times

you are correct no data label on point without optional chaining, so where i can call it so i have datalabel
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

Like I said before, I can't help you without looking at your code. There are too many variables that can cause this error. In general, call it where the point is already loaded and has dataLabels on it, but that's all I can say without the live example to see where and how you are calling this method.
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Getting point.dataLabel undefined at times

sure allow me sometime i will create and post
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

Great! I'm waiting for your response then.

Thank you!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Getting point.dataLabel undefined at times

hi

i have created the example in

https://stackblitz.com/edit/highcharts- ... service.ts


but somehow its not showing the data though in local its working,
can u plz see this
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

Hello,

Sadly, we are not able to help you without a working demo. The fact, that it's not working makes it impossible to debug it and tell you where the problem is.
Make sure to get a working application before sending it to us for debugging, for example, if you are using some external data, change it to a static one so it works in StackBlitz.

Let us know once you fix the demo,
Best regards!
Kamil Musiałowski
Highcharts Developer
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

Thank you, it is working now!

But I was not able to reproduce your issue, everything is working fine on my side. Could you please tell me the exact steps to reproduce this issue?
Also, as a side note - in line 96 you are assigning this.point to the point variable.

Later you are still using this.point. Change that to point, maybe that will save you some trouble.

Regards!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Getting point.dataLabel undefined at times

Hi kamil

that change you mentioned for line 96 for me removing this keyword is giving error pls see.

i changes the code can you plz verify chart.redraw is called or not as in my local i believe its not called so i got undefined at times.


https://stackblitz.com/edit/highcharts- ... service.ts
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

What I meant is to not change the const point = this.point. In the next few lines you are referencing to this.point again, when you can just call point, because this.point is already assigned to the point variable.

You didn't give me the steps to reproduce the issue, where chart.redraw is not called. But after checking your code, and calling the chart.redraw method, clicking the add button I don't see any errors, and the redraw method is called correctly every time.

If you would like to confirm, that chart.redraw is called, you can use the code below in your config, which will run on every redraw event.

Code: Select all

chart: {
	events: {
		redraw() {
			console.log('redraw called')
		}
	}
}
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Getting point.dataLabel undefined at times

ok i got ur point regarding this.point. Adding chart.redraw inside events function is running.

In this code i am also unable to replicate the issue but on my local its coming. Just confirm this whatever code i created its sequencing is proper?
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Getting point.dataLabel undefined at times

After inspecting your code I don't see anything unusual, everything seems fine to me. Especially with calling the redraw event.

Let us know once you encounter any other problems with your project,
Best regards!
Kamil Musiałowski
Highcharts Developer
eraka
Posts: 123
Joined: Thu Apr 28, 2022 6:55 am

Re: Getting point.dataLabel undefined at times

Hi kamil

i figured it out i was calling this.chartSet(), now i am using this.chartRef.series[0].update({ data: this.points });

it solve the problem.

But there is one issue, when we select point item, the other point labels get out of the box

https://stackblitz.com/edit/highcharts- ... service.ts

pls see the demo, if you select the second point the third one label is going out of box.

Please suggest.

Return to “Highcharts Gantt”