matija
Posts: 2
Joined: Tue Sep 27, 2022 12:07 pm

Line chart: Adding point as object for type category

Hello Highchart team,

I have basic line chart graph with several series. X are categories. Everything was OK with it, until I had to change marker for data points based on some condition. This is done at initialization time.

Here is very basic starting point:

https://jsfiddle.net/04fjevnd/13/

Here is all fine, I'm initializing data via array. When I try to initialize it from object, it fails in sense that series which was reworked doesnt get displayed:

https://jsfiddle.net/04fjevnd/22/

If I comment out line 29, it will be displayed, however points will be added to wrong categories.

Could you please advise on how this could be achieved, to add points as objects in which I may update point options.

Thanks,

Matija
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Line chart: Adding point as object for type category

Hello there,

Thank you for contacting us with your question!

The solution is really simple and can be achieved in two ways.
First one would be, to change the point.x to point.name. Because as it is stated in the API, in category type axes, if you want to refer to a certain point via its category, you have to use the name property.

DEMO: https://jsfiddle.net/BlackLabel/qr7t1b9m/
API Reference: https://api.highcharts.com/highcharts/xAxis.type

The second solution would be refering via the x value, but instead of a "Jan", "Feb", etc. category string name, use its ID from the categories array.

DEMO: https://jsfiddle.net/BlackLabel/r1z40vgq/

That's because in cartesian plane (the x, y axis chart) the x and y values have to be numbers, because they are coordinates for the points on the chart.

I hope you will find it useful, but in case of any other questions, feel free to contact us anytime,
Best regards!
Kamil Musiałowski
Highcharts Developer
matija
Posts: 2
Joined: Tue Sep 27, 2022 12:07 pm

Re: Line chart: Adding point as object for type category

Hello Kamil and thank you for your reply!

Am I missing something really obvious, but example doesnt look to be correct - samples for data set 2 are placed in the wrong category.

Thanks,

Matija

EDIT: I made mistake in the very inital example, x was set with data1. Many thanks for your prompt reply, it works as expected now!
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Line chart: Adding point as object for type category

Great to hear that Matija!

Let me know once you need anything else,
Have a great day!
Kamil Musiałowski
Highcharts Developer

Return to “Highcharts Usage”