我正在使用Dimensional Charting javascript库dc.js制作条形图。我试图按顺序显示条形图,如jan,feb,mar,apr。
我无法理解如何将这几个月按顺序排列。我附上了fiddile https://jsfiddle.net/jusjkm8j/27/。
数据采用以下格式。
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
答案 0 :(得分:2)
使用序数标度,轴将按标识函数排序。
实现此目的的一种方法是将月份格式化程序更改为
d3.time.format('%m.%b'); // 01.Jan
然后你可以在你的图表上做
spendHistChart22.xAxis().tickFormat(d => d.substr(3))
这将正确排序它们,并且只显示月份的名称。