javascript - Highcharts error #15: www.highcharts.com/errors/15 -


i'm trying use yahoo finance data generate highcharts candlestick chart http://www.highcharts.com/stock/demo/candlestick-and-volume. keep getting error: http://www.highcharts.com/errors/15 highcharts error #15

highcharts expects data sorted

this happens when trying create line series or stock chart data not sorted in ascending x order. performance reasons, highcharts not sort data, instead required implementer pre-sorts data.

my code follows.

$(function () {       $.getjson('http://websitescraper.heroku.com/?url=http://ichart.finance.yahoo.com/table.csv?s=000338.sz&callback=?', function (csvdata) {         //console.log(csvdata);         var arr = csvdata.split('\n').slice(1);          var data = [];          (var = arr.length-1; >= 0; --i) {             //console.log(arr[i]);             var line = arr[i].split(',');             line[0] = date.parse(line[0]);              line = $.map(line, function(v) {                 return parsefloat(v);             });             line = line.slice(0,6);             //var j = json.stringify(line.slice(0,0+6));             console.log(line);             data.push(line);         }         data = json.stringify(data.slice(1));         console.log(data);         run(data);     });     });  function run(data) {      // split data set ohlc , volume     var ohlc = [],             volume = [],             datalength = data.length,     // set allowed units data grouping             /*groupingunits = [[                 'week',                         // unit name                 [1]                             // allowed multiples             ], [                 'month',                 [1, 2, 3, 4, 6]             ]],*/              = 0;      (i; < datalength; += 1) {         ohlc.push([             data[i][0], // date             data[i][1], // open             data[i][2], // high             data[i][3], // low             data[i][4] // close         ]);          volume.push([             data[i][0], // date             data[i][5] // volume         ]);     }       // create chart     $('#container2').highcharts('stockchart', {          rangeselector: {             selected: 1         },          title: {             text: 'shanghai composite index historical'         },          yaxis: [{             labels: {                 align: 'right',                 x: -3             },             title: {                 text: 'ohlc'             },             height: '60%',             linewidth: 2         }, {             labels: {                 align: 'right',                 x: -3             },             title: {                 text: 'volume'             },             top: '65%',             height: '35%',             offset: 0,             linewidth: 2         }],          series: [{             type: 'candlestick',             uplinecolor: 'red',             downlinecolor: 'green',             name: 'sse',             data: ohlc,             /*datagrouping: {                 units: groupingunits             }*/         }, {             type: 'column',             name: 'volume',             data: volume,             yaxis: 1             /*datagrouping: {                 units: groupingunits             }*/         }]     }); } 

can help? lot!

the problem data = json.stringify(data.slice(1));. turns array string, therefore highstock doesn't recognize it. remove json.stringify , work fine:

data = data.slice(1); 

here's demo.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -