It is currently Wed Nov 26, 2014 6:00 am Advanced search

Some strange problem

Technical support for the Highcharts Stock package

Some strange problem

Postby tuna » Fri Feb 17, 2012 7:57 pm

Hello,
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
tuna
 
Posts: 1
Joined: Fri Feb 17, 2012 7:47 pm

Re: Some strange problem

Postby hfrntt » Wed Feb 22, 2012 11:45 pm

Hi, sorry for late reply. In Highstock data needs to be sorted ascending by x value, and x value has to be unique.
Slawek Kolodziej
Highcharts support team
hfrntt
 
Posts: 6394
Joined: Mon Aug 30, 2010 10:41 am


Return to Highstock Usage

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests