我有一个使用dc js(线条和条形图)的复合图表
然而,在使用奇异条形图/直线图表时,尺度不会动态变化
为了清晰起见,我为y轴(次要和主要两者)制作了5个刻度,但我希望Y轴的刻度和刻度间隔根据计算的值动态变化。 / p>
代码:
//Composite chart to show 2 metrics
chart3
.width(500) // (optional) define chart width, :default = 200
.height(200) // (optional) define chart height, :default = 200
.transitionDuration(500) // (optional) define chart transition duration, :default = 500
// (optional) define margins
.margins({top: 30, right: 50, bottom: 30, left: 40})
.dimension(dateDimension) // set dimension
//.group(rechfreqGroup) // set group
// (optional) whether chart should rescale y axis to fit data, :default = false
.elasticY(true)
// (optional) when elasticY is on whether padding should be applied to y axis domain, :default=0
.yAxisPadding(100)
// (optional) whether chart should rescale x axis to fit data, :default = false
//.elasticX(true)
// (optional) when elasticX is on whether padding should be applied to x axis domain, :default=0
.xAxisPadding(500)
// define x scale
.x(d3.scale.ordinal().domain(["DURING","POST1"]))
.xUnits(dc.units.ordinal)
//.renderHorizontalGridLines(true)
//.renderVerticalGridLines(true)
.legend(dc.legend().x(200).y(5).itemHeight(10).gap(3))
.title(function(d) { return "Revenue : " + d3.round(d.value.rechtotal/d.value.new_count,2) + " Frequency : " +
d3.round(d.value.rechfreq/d.value.new_count,2) ; })
.yAxisLabel("Revenue (in $)")
.rightYAxisLabel("Frequency")
.brushOn(false)
// compose sub charts, currently composite chart only supports line chart & bar chart
._rangeBandPadding(1) //workaround to fix visual stuff (dc js issues)
.compose([
dc.barChart(chart3).group(rechrevGroup,"Average Revenue").gap(10).centerBar(true).xUnits(function(){return 10;}).valueAccessor(function (p) {
return (p.value.rechtotal / p.value.new_count) ;
//return p.value.count > 0 ? p.value.rechtotal / p.value.new_count : 0;
}),
// you can even include stacked bar chart or line chart in a composite chart
dc.lineChart(chart3).group(rechfreqGroup,"Average Frequency").brushOn(false).useRightYAxis(true).colors('#000000').valueAccessor(function (p) {
return (p.value.rechfreq / p.value.new_count) ;
})
])
.yAxis().ticks(5);
chart3.rightYAxis().ticks(5);
是否可以根据计算的值进行缩放动态(此处为Y轴)? 如果没有,我可以至少设置tickValues等吗?
有关动态扩展和/或替代方案的任何方法/建议都将受到高度赞赏
更新
使用完全相同的代码here
创建了一个小提琴2个问题:
如果您有解决这些问题的任何解决方案/方法,请告诉我