如何在 dc.js 中按顺序显示月份
how to display month in sequence wise in dc.js
我正在使用维度图表 javascript 库 dc.js 制作条形图。我正在尝试按 jan、feb、mar、apr 等顺序显示条形图。
我不明白如何按顺序排列月份。我附上了小提琴 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
使用序数刻度,轴将按恒等函数排序。
实现此目的的一种方法是将您的月份格式化程序更改为
d3.time.format('%m.%b'); // 01.Jan
然后你可以在你的图表上做
spendHistChart22.xAxis().tickFormat(d => d.substr(3))
这将正确地排序它们并且也只显示月份的名称。
参见fiddle:https://jsfiddle.net/b96exL8b/
我正在使用维度图表 javascript 库 dc.js 制作条形图。我正在尝试按 jan、feb、mar、apr 等顺序显示条形图。
我不明白如何按顺序排列月份。我附上了小提琴 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
使用序数刻度,轴将按恒等函数排序。
实现此目的的一种方法是将您的月份格式化程序更改为
d3.time.format('%m.%b'); // 01.Jan
然后你可以在你的图表上做
spendHistChart22.xAxis().tickFormat(d => d.substr(3))
这将正确地排序它们并且也只显示月份的名称。
参见fiddle:https://jsfiddle.net/b96exL8b/