Having an issue parsing a string array for Highcharts consumption. The chart renders when values are static, but not when passed as an array. I have validated the string being parsed here.
The main issue appears to be with this specific line:
//This works
chart.addSeries({name: this.series_name, color: this.series_color, data: [[0.129, 0.066], [0.029, 0.218], [-0.113, 0.231]]});
//This does not work
chart.addSeries({name: this.series_name, color: this.series_color, data: series_clean});
Code snippet:
$(document).ready(function() {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'scatter',
zoomType: 'xy'
},
series: [
{data: []}
]
});
function reloadData() {
$.ajax({
type: 'GET',
url: "...",
dataType: "JSON"
}).done(function(data) {
//Remove existing series from chart
while(chart.series.length > 0)
chart.series[0].remove(true);
var i = 0;
$.each(data.users, function(firstIndex, user) {
$.each(user, function() {
//Parse incoming data array to float type
var series_clean = new Array();
var series_data_groups = this.series_data.split("|");
for(var j = 0; j < series_data_groups.length; j++) {
var series_data_values = series_data_groups[j].split(",");
var x = parseFloat(series_data_values[0]).toFixed(3);
var y = parseFloat(series_data_values[1]).toFixed(3);
series_clean.push([x, y]);
}
//Push series to chart
chart.addSeries({name: this.series_name, color: this.series_color, data: series_clean});
i++;
});
});
chart.redraw();
});
}
setInterval(function(){reloadData(); }, 2000);
});
Error in console:
Uncaught Error: Highcharts error #14: www.highcharts.com/errors/14
at Object.a.error (highcharts.js:10)
at n.setData (highcharts.js:284)
at n.init (highcharts.js:277)
at a.Chart.initSeries (highcharts.js:243)
at highcharts.js:317
at a.fireEvent (highcharts.js:29)
at a.Chart.addSeries (highcharts.js:317)
at Object.<anonymous> (chart_scatter_live2.html:109)
at Function.each (jquery-3.2.0.min.js:2)
at Array.<anonymous> (chart_scatter_live2.html:95)