我使用dc.js构建系列图表。我无法根据需要设置Y轴的开始和结束。有人可以建议如何实现从90开始而不是从0开始的Y轴?理想情况下,我想将Y轴启动设置为数据值的最小值并结束为数据值的最大值。设置直流系列图中的Y轴范围
代码:
d3.csv("data/compareData.txt", function(data) {
ndx = crossfilter(data);
runDimension = ndx.dimension(function(d) {return [+d3.time.format.iso.parse(d.timestamp), +d.meterid]; });
runGroup = runDimension.group().reduceSum(function(d) { return +d.voltagemagnitude*100; });
testChart
.width(768)
.height(480)
.chart(function(c) { return dc.lineChart(c).interpolate('basis'); })
.x(d3.time.scale().domain([1366621166000, 1366621179983]))
.y(d3.scale.linear().domain([90, 100]))
.brushOn(false)
.yAxisLabel("Measured Speed km/s")
.xAxisLabel("Run")
.elasticY(true)
.dimension(runDimension)
.group(runGroup)
.mouseZoomable(false)
.seriesAccessor(function(d) {return "PMU: " + d.key[1];})
.keyAccessor(function(d) {return +d.key[0];})
.valueAccessor(function(d) {return +d.value;})
.legend(dc.legend().x(350).y(350).itemHeight(13).gap(5).horizontal(1).legendWidth(140).itemWidth(70));
testChart.yAxis().tickFormat(function(d) {return d3.format(',d')(d);});
testChart.margins().left += 40;
dc.renderAll();
});
工作!我必须设置.yAxisPadding(-1)才能显示。但你的回答至少让我的y轴蜱显示。 –
@MWWiLofDoom:谢谢! –