I think you cannot return values from the success call instead you would need to call a function instead. So set up your function that initializes your chart, and in the ajax success call that function with the data
With your code example
function visitorData (data) {
$('#chart1').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Average Visitors'
},
xAxis: {
categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
},
yAxis: {
title: {
text: 'Number of visitors'
}
},
series: data,
});
}
$(document).ready(function() {
$.ajax({
url: '/visitdata',
type: 'GET',
async: true,
dataType: "json",
success: function (data) {
visitorData(data);
}
});
});