简体   繁体   中英

Highcharts datetime axis, how to disable time part (show only dates)?

My chart is displaying data day-by-day (user and system sent SMS/Newsletters). So time part is not relevant and unnecessary. Here is an example: http://jsfiddle.net/uaxZP/1/ where time "12:00" is displayed.

How can I force Highcharts to never display the time part in a "datetime" axis ?

EDIT : Highcharts will display dates w/wo times based on chart or screen size. I've updated jsfiddle removing some data and now it's displaying also time parts.

You can intercept the x-axis label function and change it's output. In my example, I've changed it to render short dates:

http://jsfiddle.net/uaxZP/3/

{ xAxis: 
    labels: {
        formatter: function() {
             return Highcharts.dateFormat("%b %e", this.value);
        }
    }
}

        

The xAxis.labels.formatter property allows control over this. You also may notice I'm using Highcharts.dateFormat, which is a utility function for rendering dates. This is not mandatory, but it's a nice built in feature. Documentation on the xAxis formatter is here:

http://www.highcharts.com/ref/#xAxis-labels--formatter

The easiest way to do is using "minTickInterval"

xAxis: {
       minTickInterval: 24 * 3600 * 1000
}

http://api.highcharts.com/highcharts#xAxis.minTickInterval

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM