我在为lineChart绘制rangeChart时遇到麻烦。
d3.tsv("demo.tsv").then(function(someData) {
drawMarkerSelectsome(someData);
});
function drawMarkerSelectsome(someData) {
parseDate = d3.timeParse("%m/%d/%Y");
someData.forEach(function(d) {
d.dd = parseDate(d.txndatetime);
d.month = d3.timeFormat("%m")
});
xf = crossfilter(someData);
all = xf.groupAll();
// Dimension by full date
dateDim = xf.dimension(function(d) { return d.dd; });
// Dimension by month
moveMonths = xf.dimension(function (d) {
return d.month;
});
numRecordsByDate = dateDim.group().reduceCount();;
numRecordsByMonth = moveMonths.group().reduceCount();
minDate = dateDim.bottom(1)[0].dd;
maxDate = dateDim.top(1)[0].dd;
timeChart = dc.lineChart("#time-chart",groupname)
.renderArea(true)
.width(940)
.height(200)
.transitionDuration(3000)
.margins({top: 10, right: 50, bottom: 20, left: 40})
.dimension(dateDim)
.mouseZoomable(true)
.rangeChart(volumeChart)
.elasticY(true)
.renderHorizontalGridLines(true)
.renderVerticalGridLines(true)
.brushOn(false)
.group(numRecordsByDate)
.x(d3.scaleTime().domain([minDate, maxDate]))
.round(d3.time.day.round)
.xUnits(d3.time.days)
.elasticY(true);
volumeChart.width(940)
.height(60)
.margins({top: 5, right: 50, bottom: 20, left: 40})
.dimension(dateDim)
.group(numRecordsByMonth)
.centerBar(true)
.gap(1)
.alwaysUseRounding(true)
.colors(['#D62728'])
.x(d3.scaleTime().domain([minDate, maxDate]))
.round(d3.time.month.round)
.xUnits(d3.time.months);
我尝试保持Dimension(dateDim)不变,并按照此处的讨论{dc.js - rangeChart bars disappearing when filtered out)更改了组,但是我一直收到以下错误。
不确定代码有什么问题。我正在使用dc.js v.3.0.7和d3.js v.5.7.0。
答案 0 :(得分:1)
该错误表明volumeChart
未定义。您没有显示它的初始化位置,但我想它没有初始化。
您必须在调用volumeChart
之前将lineChart或barChart实例化为.rangeChart(volumeChart)
如果需要,您仍然可以在设置timeChart
之后设置其参数。