Been struggling to get my data right from the array to the chart. This is my code,
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "<%=ResolveUrl("Services/HighstockService.asmx/TempData") %>",
data: "{}", /* Sending specific indata */
dataType: "json",
success: function (Result) {
//debugger;
Result = Result.d;
var tempData = [];
for (var i in Result) {
var serie = new Array("[" + parseInt(Result[i].Date.substr(6)) + "," + Result[i].Value + "],");
tempData.push(serie);
}
DrawTempChart(tempData);
},
error: function (Result) {
alert("Error");
}
});
});
function DrawTempChart(tempData) {
debugger;
$('#tempChart').highcharts('StockChart', {
title: {
text: 'AAPL Stock Price'
},
type: 'datetime',
dateTimeLabelFormats: {
second: '%Y-%m-%d %H:%M:%S',
minute: '%Y-%m-%d %H:%M',
hour: '%Y-%m-%d %H:%M',
day: '%Y %m-%d',
week: '%Y %m-%d',
month: '%Y-%m',
year: '%Y'
},
series: [{
name: 'AAPL',
data: [tempData],
}]
});
}
</script>
I am adding the brackets and comma to every index in the array to follow the structure of how highstocks accepts data. When debugging, I then receive data like this: "[1418017375000,33],".
I need to parseInt the Date due to javascript adding parenthesis and forward slashes when moving it from Web Services. I am unsure if it gets rightly formatted in the javascript to work in the chart.
Since I really can't debug the DrawTempChart function, I don't actually know how the array is sent into that function. Anyone that can see what I am doing wrong?
[edit] Should probably be added that the closest I have come to an output is to show only the last index in the array on the chart.
Copyright Notice:Content Author:「JakobMiller」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27465457/adding-data-to-highstocks-by-pushing-array