I've been trying to implement Highstock on my website using the basic line example:
- Code: Select all
$(function() {
$.getJSON('http://62.75.165.214/highstock/examples/basic-line/json.php?filename=aapl-c.json&callback=?', function(data) {
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container'
},
rangeSelector : {
selected : 4
},
title : {
text : 'AAPL Stock Price'
},
series : [{
name : 'AAPL',
data : data,
tooltip: {
yDecimals: 2
}
}]
});
});
});
As you can see here it doesn't work. In fact the whole thing crashes.
When I replace my URL with the URL of the example ( http://www.highcharts.com/samples/data/ ... &callback=? ) it works flawlessly.
This is how my json.php looks like:
- Code: Select all
<?php
header('filename="' . $_REQUEST['filename'] . '"');
// Set CSV feed
$feed = 'http://62.75.165.214/highstock/AAPL.csv';
// Function to convert CSV into associative array
function csvToArray($file, $delimiter) {
if (($handle = fopen($file, 'r')) !== FALSE) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
for ($j = 0; $j < count($lineArray); $j++) {
$arr[$i][$j] = ($j == 0) ? strtotime($lineArray[$j])*1000 : floatval($lineArray[$j]);
}
$i++;
}
fclose($handle);
}
return $arr;
}
$data = csvToArray($feed, ',');
// Delete first line
array_shift($data);
// Print it out as JSONP
echo $_REQUEST['callback'].'(';
echo json_encode($data);
echo ');';
?>
The error has to be somewhere in this line:
- Code: Select all
$arr[$i][$j] = ($j == 0) ? strtotime($lineArray[$j])*1000 : floatval($lineArray[$j]);
specifically this segement
- Code: Select all
strtotime($lineArray[$j])*1000
because when I replace this with a plain integer for the timecode it works. For example
- Code: Select all
100000000*$i
Just times from the .csv won't work.
Any help is appreciated.
Regards,
tuna