Highcharts time X axis

2019-07-24 14:25发布

问题:

I would like to ask if somebody knows how to set X axis in Highcharts to time. My aplication is taking data from database and the frequency of the samples is 250ms. I want the X axis not to show counted values but something like time. I render 2500 values at once so that means 10 secs. The best would be to have on X axis and a mark there every 0.5 sec that means every 125 samples a mark. Like (0 samples = 0 sec);(125 samples = 0,5 sec);(500 samples = 1 sec);(725 samples = 1.5 sec)

Thank you for your opinions.....

                                chart () {
                                    var options = {
                                        chart: { 
                                            renderTo: 'services',
                                            type: 'line', 
                                            animation: 'false'
                                        },

                                      plotOptions: {
                                            series: {
                                                animation: {
                                                    duration: 10000
                                                }
                                            }
                                        },

                                        series: [{marker: {
                                                    enabled: false
                                                }}]
                                      };

回答1:

You can supply a custom label formatter. For example...

xAxis: {
    labels: {
        formatter: function () {
            return (baseTime + (this.value / 500)) + " sec";
        }
    }
},

where baseTime is the time of the first data point.

Documentation for custom label formatter can be found at...

http://api.highcharts.com/highcharts#xAxis.labels.formatter