我正在使用以下代码在dc中绘制一个带有两个y轴的复合图表来比较两个值(今年和去年):
compositeChart.width(1200)
.height(240)
.margins({top: 10, right: 100, bottom: 70, left:80})
.transitionDuration(800)
.dimension(depValue)
.elasticY(true)
.x(d3.scale.ordinal().domain(["AUTO & TIRES","BABY", "CLOTHING", "ELECTRONICS", "GARDEN", "GROCERY", "HEALTH", "HOME", "HOME IMPROVEMENT", "PHOTO", "SPORTS", "TOYS", "VIDEO GAMES"]))
.xUnits(dc.units.ordinal)
.renderHorizontalGridLines(true)
.compose([
dc.barChart(compositeChart)
.group(group,"This Year")
.clickFilterBehavior("replace")
.valueAccessor(function (d) {
console.log(d.value);
return d.value;
}),
dc.barChart(compositeChart)
.group(group1,"Last Year")
.valueAccessor(function (d) {
console.log(d.value);
return d.value;
})
.clickFilterBehavior("replace")
.title(function (d) {
var value = d.data.value ? d.data.value : d.data.value;
if (isNaN(value)) value = 0;
return dateFormat(d.data.key) + "\n" + numberFormat(value);
})
.colors(["orange"])
.useRightYAxis(true)
])
.yAxisLabel("This Year")
.rightYAxisLabel("Last Year")
.renderHorizontalGridLines(true)
.renderlet(function (chart) {
chart.selectAll("g._1").attr("transform", "translate(" + 100 + ", 0)");
});
图表很好,但问题是Y轴(左右)的比例不相同,因此即使去年的值小于今年,该条看起来也高于今年我有没有办法将图表的比例设置为相同?任何帮助都会受到赞赏。!!!