酒窝时间格式杂耍 [英] Dimple Time Format Juggling

查看:99
本文介绍了酒窝时间格式杂耍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对酒窝处理日期的方式感到非常困惑(或者也许只是D3).

I am very confused by the way dates are handled by dimple (or maybe it is just D3).

我的问题可以分为两个问题:

My problem can be divided in two questions:

  1. 我的日期以%Y-%m-%d %H:%M:%S格式显示在我的csv文件中.为了将它们转换为日期对象,我目前使用与香草" d3中相同的循环.

  1. My dates come as a column in my csv file in the format %Y-%m-%d %H:%M:%S. In order to convert them to date objects, I currently use the same loop I used to have in "vanilla" d3.

data.forEach(function (d) {
   var format = d3.time.format("%Y-%m-%d %H:%M:%S");
   d.Date = format.parse(d.Date);
});

有更快的方法吗?也许使用 timeField函数?还是 dateParseFormat ?我可能是错的,但那些功能看起来像帮助处理日期的助手.

Is there a quicker way to do this with? Maybe with the timeField function? Or dateParseFormat? I might be wrong but those functions looks like helpers to handle dates.

我想控制时间对象的主要原因是能够重新格式化它们.文档似乎表明可以使用 tickFormat函数为了这.不幸的是,我也没有使用它.我最好的猜测:

The main reason why I want to control my time objects is to be able to reformat them. Documentation seems to indicate that the tickFormat function can be used for this. Unfortunately I also failed at using it. My best guess:

var x = myChart.addCategoryAxis("x", "Date");

x.tickFormat(d3.time.format("%Y-%m")); // For example for a year-month format

仅返回

x.tickFormat不是函数

非常感谢

泽维尔

推荐答案

时间格式与时间轴有关.如果要使用时间轴,则不需要循环,只需使用:

The time formatting relates to time axes. You don't need your loop if you want to use the time axis, just use:

myChart.addTimeAxis("x", "Date", "%Y-%m-%d %H:%M:%S", "%Y-%m");

其中%Y-%m-%d%H:%M:%S"是您的输入,而%Y-%m"是您的输出格式. "x.tickFormat不是函数"错误的原因是它不是:).您可以根据需要将时间轴使用的tickFormat设置为属性,但如果使用上述工厂方法,则不需要设置此格式:

where "%Y-%m-%d %H:%M:%S" is your input and "%Y-%m" is your output format. The reason for the "x.tickFormat is not a function" error is that it isn't :). You can set the tickFormat used by the time axis as a property if you wish but it isn't required if you use the factory method above:

myTimeAxis.tickFormat = "%Y-%m";

但这仅适用于时间轴.

可以在此处找到运行中的时间轴示例:

An example of the time axes in action can be found here:

http://dimplejs.org/advanced_examples_viewer.html?id=advanced_time_axis

希望有帮助

约翰

这篇关于酒窝时间格式杂耍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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