score:1

Accepted answer

the idea behind using highchart stockchart is it uses x-axis label as timestamp.

solution to "how can i make my x-axes to use my own timestamp api data? " should be converting data[i].timestamp by parsing to real timestamp and create nested array of 'accelero_x' and pass that array to series data.

highcharts.getjson('https://gmlews.com/api/data', function (data) {
console.log(data);
var accelero_x = [], timestamp = [];
      for (var i=0; i<data.length; i++){
      //modification start -----
      let inarr = [];
      let trimdate = data[i].timestamp.split('t')[0]; // here we have many ways to extract only the date correctly
      inarr.push(date.parse(trimdate));
      inarr.push(data[i].accelero_x);
        accelero_x.push(inarr);
      //modification end -----
        timestamp.push(data[i].timestamp);
     }
      console.log(accelero_x);
      console.log(timestamp); 
// create the chart
highcharts.stockchart('container', {

    rangeselector: {
        selected: 1
    },

    title: {
        text: 'accelero x'
    },


    series: [{
        name: 'accelero x',
        data: accelero_x,
        type: 'spline',
        tooltip: {
            valuedecimals: 2
        }
    }]
 });
 }); 

demo: https://jsfiddle.net/jinny/jrhz3ty7/20/

score:0

  • here is an api options how to set the range selections options: https://api.highcharts.com/highstock/rangeselector.buttons

  • your second part of the question - highcharts requires data in the following formats:

    • array of values - like: [10,20,30,40] - highcharts reads it as an array of y values and set default x values - 1, 2, 3, 4

    • array of arrays - like: [[3, 24], [5, 42], [8,33]] - where first value in the array is an x and the second one is the y - [x, y]

    • array of objects - like: [{x: 3, y: 24}, {x: 5, y: 42}] - here is quite obvious

the xaxis could be a datatime type, where x value is a value in milliseconds format, that's mean you will need to convert your data into the milisecond value to set it, like here: https://jsfiddle.net/blacklabel/w9hznsey/


Related Query

More Query from same tag