如果我使用yAxis()ticks或tick格式化,我有这个代码会引发错误。
revSpendCompositeChart
.width(400).height(180)
.elasticX(true)
.transitionDuration(1000)
.dimension(dateDim)
.elasticY(true)
.zoomOutRestrict(true)
.x(d3.time.scale().domain([minDate,maxDate]))
.renderHorizontalGridLines(true)
.compose([
dc.lineChart(revSpendCompositeChart)
.dimension(dateDim)
.colors('orange')
.group(spendDateGroup, "Spend"),
dc.lineChart(revSpendCompositeChart)
.dimension(dateDim)
.colors('green')
.group(revenueDateGroup, "Revenue")
])
.brushOn(false);
然而,这会引发错误,因为未定义的函数。
revSpendCompositeChart
.width(400).height(180)
.elasticX(true)
.transitionDuration(1000)
.dimension(dateDim)
.elasticY(true)
.zoomOutRestrict(true)
.x(d3.time.scale().domain([minDate,maxDate]))
.yAxis().tickFormat(function (v) {
return v + '%';
})
.renderHorizontalGridLines(true)
.compose([
dc.lineChart(revSpendCompositeChart)
.dimension(dateDim)
.colors('orange')
.group(spendDateGroup, "Spend"),
dc.lineChart(revSpendCompositeChart)
.dimension(dateDim)
.colors('green')
.group(revenueDateGroup, "Revenue")
])
.brushOn(false);
该文档没有说明这一点。但我发现折线图支持yAxis()函数。因此,由于我的复合图表是两个折线图,我需要让它工作。
答案 0 :(得分:0)
虽然大多数dc.js方法链,但有些链不能相同 宾语。 xAxis返回一个不是图表的d3轴对象。如果你 访问图表的轴对象,最后执行或单独执行 行:
var chart = dc.barChart(...).this(...).that(...);
var xAxis = chart.xAxis().tickFormat(...).ticks(...);
var yAxis = chart.yAxis().tickFormat(...).ticks(...);