Hilmi
Posts: 9
Joined: Fri Jul 15, 2022 10:06 am

How to select the JSON key to be used in y axis?

Sat Sep 23, 2023 3:22 pm

I have the following data in JSON format:

Code: Select all

[
	{"id": 1, "x": 8000000, "y": 15800, "count": 120},
	{"id": 2, "x": 12200000, "y": 14400, "count": 150},
	{"id": 3, "x": 17020000, "y": 16100, "count": 250},
	{"id": 4, "x": 74780000, "y": 17800, "count": 310}
]

When I plot a 2D line chart, Highcharts will plot the "x" values in X axis and "y" values in Y axis. How do I make Highcharts ignore the "y" values and instead use the "count" values in Y axis?

Thanks in advance.

CSommer
Posts: 56
Joined: Mon Jun 27, 2016 12:27 am

Re: How to select the JSON key to be used in y axis?

Sun Sep 24, 2023 9:03 pm

Either change your JSON request, use seriesMapping or parse the JSON string into the fields you require.

jedrzej.r
Posts: 531
Joined: Tue Jan 24, 2023 11:21 am

Re: How to select the JSON key to be used in y axis?

Mon Sep 25, 2023 9:16 am

Hi!

On top of that, you can also map the data by using Array.map JavaScript method, so that you pass the right data object into the chart config. Taka a glance at below example to see it in action.

Demo: https://jsfiddle.net/BlackLabel/ewqvf9g3/

Reference: https://developer.mozilla.org/en-US/doc ... /Array/map

Let me know if you have any further questions!
Best regards!
Jędrzej Ruta
Highcharts Developer

Hilmi
Posts: 9
Joined: Fri Jul 15, 2022 10:06 am

Re: How to select the JSON key to be used in y axis?

Mon Oct 02, 2023 1:29 pm

Thanks for both of the answers. They certainly helped me to get the intended outcomes. :)

Return to “Highcharts Usage”