JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Highcharts error #15

Hello, It's an error #15 on a chart, I know what it means (Data is not sorted in ascending order), but I don't know how to fix my problem. Of course I did some research before posting, but nothing solved my problem. I would also like an explanation so that I don't have the same problem again.
https://jsfiddle.net/JP5401/rj7qm8ew/12/
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

Hi,

Thanks for the question!

Exactly, Highcharts error 15 states that the data should be sorted in ascending order. It helps with rendering the chart. In your case, the points (x, y) are not sorted by (x) which is why this error shows up.

Here's a simplified demo: https://jsfiddle.net/BlackLabel/p05hvon6/1/

Let me know if that helps.

Best regards,
Jakub
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

Good morning,
Thank you for your reply.
The problem is that I can't adapt your code to my example. I have a blank page each time.
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

Hi,

In the previous demo I've showed you how you can map and sort your data. If you perform these actions, the error should disappear.

Here's a demo with your data: https://jsfiddle.net/BlackLabel/vhd37Ly1/

Let me know if that solves your problem.

If not, please send me a demo of your example where only a blank page shows.

Regards,
Jakub
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

I'm sorry, but it doesn't work.
I have a blank page, I must do something wrong or I forget something
https://jsfiddle.net/JP5401/rj7qm8ew/15/
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

As you could read from the console error, you have declared a variable named seriesData twice, which causes a JS error.

Here's a demo without this error: https://jsfiddle.net/BlackLabel/9bvntdj2/

Let me know if everything's working as it's supposed to.

Regards,
Jakub
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

There, I don't understand anything anymore, I always have error 15. I don't see at all what I can change.
https://jsfiddle.net/JP5401/rj7qm8ew/18/
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

If you take a closer look at your arrays you'll notice that your outcome array had a different length than the date array. This caused the error as the arrays you passed to series.data had undefined.

Here's a demo: https://jsfiddle.net/BlackLabel/k57t8cjr/

Jakub
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

Yes it is normal that the table of results is longer than that of dates, this graph must work with a database which takes into account the data of the current year.
In your example, we find 1,672,527,600 (First value) in the average temperature whereas it is the tstamp of the first date of the graph, ie January 1, 2013 at 00h00min00sec.
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

Okay, but if the table of results is longer than that of the dates then with your method you get an array with elements [undefined, result] because there are not enough dates to map results. That's why you had this error.

I'm not really sure how I could help you with that. If you follow these, you will not get the error:
- series.data requires data sorted by x
- you can pass an array of pairs (x, y) and x cannot be undefined

You need to figure out what is it that you want in the chart, create data arrays satisfying the conditions above, and pass it to series.data.

I'd recommend you preprocess your data after you get it from your database and before you pass it to chart so that it is exactly in the form you want Highcharts to present it.

Regards,
Jakub
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

Ok fine, I understand what you mean, I will do some tests.
Is it possible to make this graph by displaying outcome values only when date and income values are displayed on the graph. In fact, displayed on the graph the outcome value only if the date and income are displayed on the graph. In my example that the outcome values remain invisible after February 28, 2023.
I hope I was clear enough in my explanation.
https://jsfiddle.net/JP5401/rj7qm8ew/21/
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

I'd recommend you generate outcomeData and incomeData & put it in series.data so that you have the result you want.

I'm not sure how exactly do you want your chart to look like.

By putting [date, income] and [date, outcome] pairs (where dates are the same for both series) to series.data you should have 2 points for each date - income, outcome, like here: https://jsfiddle.net/BlackLabel/k04a7y8z/

Highcharts generates charts based on the series.data you pass to the config so you need to think carefully about how you want your chart to look like and preprocess your data accordingly.

Could you please explain to me exactly what is it that you're trying to achieve?
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

As I told you, my data is extracted from a database.
On a table I retrieve the average temperature and the date. On another table I get the normal average temperatures.
This graph compares the difference between the average temperature and the normal average temperature over a full year from January 1 to December 31. Here is an example of a full year, the year 2021. I would like my graph to look like this example.
https://www.meteo-jarny.com/test/graph-test9.php
As you can see, there is no error 15 because the two series average temperature, normal average temperature and the dates have the same length, ie 365 days.
The problem arises on the current year because I retrieve the normal average temperatures on my table (365 days) and the average temperature and the date on another table which stops at February 28 on this example.
https://jsfiddle.net/JP5401/rj7qm8ew/12/
Until I get the full year, I'll get error 15. And I don't know how to get around this problem.
I give you the PHP part of my graph with which I retrieve my data on my tables, it may help you to understand better

Code: Select all

$query=mysqli_query($conn,$sql);                  
$list=mysqli_fetch_array($query);     

$start = mktime(0,0,0,1,1,date("2021"));
$stop = mktime(23,59,59,12,31,date("2021"));					  

$sql = "SELECT tstamp, temp_moy  FROM minimaxiarchive WHERE ((tstamp) between '$start' AND '$stop') ";  
$query=mysqli_query($conn,$sql);                   
$i=0;
while ($list = mysqli_fetch_assoc($query)) { 
$dtime[$i] = $list['tstamp']*1000;   
$dmean[$i]=$list['temp_moy']*1;							
$i++;
}
$sql = "SELECT jour, mois, norme_temp_moy  FROM normale_journaliere_365 ";  
$query=mysqli_query($conn,$sql);                   
$i=0;
while ($list = mysqli_fetch_assoc($query)) { 
   
$dnorme[$i]=$list['norme_temp_moy']*1;	
$ecart[$i] = $dmean[$i] - $dnorme[$i];	
					
$i++;
}

mysqli_close($conn);	   	
?>
jakub.s
Posts: 1157
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts error #15

In this demo (https://www.meteo-jarny.com/test/graph-test9.php) you have full data (outcome.length === income.length === date.length) which is not the case for the data you've sent, where:
- outcome.length is 365
- income.length is 59
- date.length is 59

So there's no way to create a chart with a full year of data if you don't have income data for the entire year.

Here's a demo showing only the range for which you have full data: https://jsfiddle.net/BlackLabel/rgume1hj/

Regards,
Jakub
Jakub
Highcharts Developer
JP54
Posts: 44
Joined: Sun Apr 19, 2020 3:50 pm

Re: Highcharts error #15

Your example doesn't work for me, so if it's not possible, I'll drop my graph. Thanks for your help

Return to “Highcharts Stock”