[英]d3js X axis data by quarter sub grouped by year
I'm struggling to create a line chart that has two X axes and subgroupings for the year. 我正在努力创建一个折线图,该折线图具有该年的两个X轴和子分组。 So for example if I have 4 quarters, (Q3,Q4,Q1,Q2) and Q3,Q4 belong to the year 2014 while Q1,Q2 belong to the year 2015 i would be able to depict this on the second X axis. 因此,例如,如果我有4个季度,(Q3,Q4,Q1,Q2)和Q3,Q4属于2014年,而Q1,Q2属于2015年,我可以在第二个X轴上进行描述。 I have an example of this in the imgur link posted below, and a somewhat similar example that uses months instead of quarters. 我在下面发布的imgur链接中有一个示例,还有一个类似的示例,它使用月份而不是季度。 Does anyone have any insight or examples as to how I can accomplish this? 是否有人对我如何实现此目标有任何见解或示例?
http://imgur.com/KXjXbxc http://imgur.com/KXjXbxc
http://jsfiddle.net/bhyvn5hv/ http://jsfiddle.net/bhyvn5hv/
var xAxis1 = d3.svg.axis()
.scale(x)
//.ticks(d3.time.months)
.tickFormat(monthformat)
.tickSize(5,0)
.orient("bottom");
var xAxis2 = d3.svg.axis()
.scale(x)
.ticks(d3.time.years, 1)
.tickFormat(yearformat)
.tickSize(5,0)
.orient("bottom");
How about this? 这个怎么样? JSFiddle 的jsfiddle
var quarter = function(date, i){
if(i > 0){
var date2 = new Date();
date2.setMonth(date.getMonth() - 1);
q = Math.ceil(( date2.getMonth()) / 3 );
return "Q" + q;
}
}
var xAxis3 = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.months, 3)
.tickSize(5, 0)
.tickFormat(quarter);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (height + 25) + ")")
.call(xAxis3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.