如何在dc.js中按顺序显示月份 [英] how to display month in sequence wise in dc.js

查看:136
本文介绍了如何在dc.js中按顺序显示月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Dimensional Charting javascript库dc.js制作barchart。我试图按顺序显示barchart像jan,feb,mar,apr。



我不明白如何把月份顺序。我附加了fiddile https://jsfiddle.net/jusjkm8j/27/



数据格式如下。

  Sku Stars合作伙伴审查日期
KBU12 5亚马逊优先于r。 02/05/2016
KBU12 5 Amazon Gorgeous fixture 05/06/2016
KBU12 2 Amazon真棒值! 02/02/2016
KBU12 2 Homedepot Kitchen Remodel 06/09/2016
KPF1650 3 Homedepot Wow 02/08/2016
KPF1650 4 Homedepot Sharp! 05/04/2015
KPF1650 5 Homedepot酷设计05/05/2015
KPF1650 1 Amazon美容09/08/2015
KPF1650 2 Amazon非常开心09/11/2016
GV-100 3 Amazon优质12/12/2015
GV-100 5 Homedepot爱它01/03/2015
GV-100 1 Homedepot Sad我不得不归还12/10/2014
GV-100 4 Homedepot美丽但坚固12/11/2014
GV-100 2 Homedepot厨房龙头10/04/2014
KBU24 3建立我喜欢龙头的外观04/05/2014
KBU24 5构建没有06/07/2016的商业风格
KBU24 4构建非常酷06/07/2014
KBU24 1构建优秀! 01/04/2014
KBU24 3建立一个美丽的船只水槽07/06/2013
KBU24 5亚马逊美丽添加05/04/2013


解决方案

使用顺序缩放,轴将由身份函数排序。



一种实现方法是将您的月份格式化工具更改为

  d3.time.format('%m。 %b'); // 01.Jan 

然后你可以在你的图表上做

  spendHistChart22.xAxis()。tickFormat(d => d.substr(3))


请参阅fiddle: https://jsfiddle.net/b96exL8b/


I'm making a barchart using the Dimensional Charting javascript library dc.js. I am trying to display barchart in sequence like jan,feb,mar,apr.

I can't understand how to put the months in sequence. I have attached fiddile https://jsfiddle.net/jusjkm8j/27/ .

The data is in the following format.

 Sku      Stars partner review  Date
 KBU12     5       Amazon   Preferred over the r.   02/05/2016
 KBU12     5       Amazon   Gorgeous fixture    05/06/2016
 KBU12     2       Amazon   Awesome value!  02/02/2016
 KBU12      2      Homedepot    Kitchen Remodel 06/09/2016
 KPF1650    3   Homedepot   Wow 02/08/2016
 KPF1650    4   Homedepot   Sharp!  05/04/2015
 KPF1650    5   Homedepot   cool design 05/05/2015
 KPF1650    1   Amazon  Beautiful   09/08/2015
 KPF1650    2   Amazon  Very happy  09/11/2016
 GV-100     3   Amazon  Great quality   12/12/2015
 GV-100     5   Homedepot   Love it 01/03/2015
 GV-100     1   Homedepot   Sad I had to return it  12/10/2014
 GV-100     4   Homedepot   Beautiful But Stiff 12/11/2014
 GV-100     2   Homedepot   Kitchen Faucet  10/04/2014
 KBU24      3   Build       I like the look of faucet   04/05/2014
 KBU24      5   Build       Commercial style without    06/07/2016
 KBU24      4   Build       Very Cool   06/07/2014
 KBU24      1   Build       Excellent!  01/04/2014
 KBU24      3   Build       A beautiful Vessel Sink 07/06/2013
 KBU24      5   Amazon      Beautiful addition  05/04/2013

解决方案

with an ordinal scale the axis will be ordered by the identity function.

One way to achieve this would be to change your month formatter to

d3.time.format('%m.%b'); // 01.Jan

Then you can on your chart do

spendHistChart22.xAxis().tickFormat(d => d.substr(3))

this will order them correctly and also display only the name of the month.

See fiddle: https://jsfiddle.net/b96exL8b/

这篇关于如何在dc.js中按顺序显示月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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