更改为Google图表中日期时间数据的24小时格式 [英] Change to a 24 hour format for datetime data in Google Charts

查看:139
本文介绍了更改为Google图表中日期时间数据的24小时格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Charts API使用javascript绘制数据。日期时间数据视图的默认格式是12小时制。如何更改视图以显示24小时格式?下面显示了一个示例代码,其中使用了默认的日期时间格式:

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 format? An example of code is shown below, where the default datetime format is used:

var price_data = new google.visualization.DataTable();
         price_data.addColumn('datetime','Time');
         price_data.addColumn('number','Price [øre/KWh]');

price_data.add_row([new Date(2013,23,3,4,5),3])
price_data.add_row([new Date(2013,1,5,4,5),9])

var options = {
      title: 'Price'
    };

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);


推荐答案

您需要使用 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);

您可以通过设置 hAxis.format 选项:

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

日期格式支持大多数ISO日期格式设置模式

这篇关于更改为Google图表中日期时间数据的24小时格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆