Change to a 24 hour format for datetime data in Google Charts

前端 未结 2 1687
走了就别回头了
走了就别回头了 2021-02-15 06:16

Im plotting data with javascript using the Google Charts API. The default format for datetime data view is the 12 hour am/pm format. How can I change the view to show a 24 hour

2条回答
  •  猫巷女王i
    2021-02-15 06:57

    You need to format the datetimes using a DateFormatter.

    // format dates
    // ex: "August 5, 2013 1:45 PM" formatted as "05/08/2013 13:45"
    var dateFormatter = new google.visualization.DateFormat({pattern: 'dd/MM/yyyy HH:mm'});
    dateFormatter.format(data, 0);
    

    You can format the axis labels by setting the hAxis.format option:

    var options = {
        hAxis: {
            format: 'dd/MM/yyyy HH:mm'
        }
        title: 'price'
    };
    

    The date formats support most of the ISO date formatting patterns.

提交回复
热议问题