如何解决DC.JS OnClick函数的控制台误差?
我目前正在使用D3.JS版本7.4.4和DC.JS版本4.0.0。 以下是使用相同数据制作条形图和2个饼图的代码:
dataCount = dc.dataCount('#data-count');
var CountryChart= new dc.PieChart('#Country');
var WaterTypeChart = new dc.PieChart("#WaterType");
var yearChart = new dc.BarChart("#Year")
d3.csv("file.csv").then(function(data) {
var ndx =crossfilter(data);
var all= ndx.groupAll();
var yearDim= ndx.dimension(function(d){ return d["Year"]});
var CountryDim= ndx.dimension(function(d){ return d["Country"]});
var JournalDim= ndx.dimension(function(d){ return d["Journal"]});
var WaterTypeDim= ndx.dimension(function(d){ return d["WaterType"]});
var CountryGroup = CountryDim.group();
var WaterTypeGroup = WaterTypeDim.group();
var yearGroup= yearDim.group();
CountryChart
.width(220)
.height(200)
.slicesCap(20)
.innerRadius(20)
.dimension(CountryDim)
.group(CountryGroup)
.transitionDuration(500);
WaterTypeChart
.width(220)
.height(200)
.ordinalColors(['#0096FF', '#40E0D0', '#228B22'])
.slicesCap(4)
.innerRadius(10)
.dimension(WaterTypeDim)
.group(WaterTypeGroup);
yearChart
.width(550)
.height(350)
.dimension(yearDim)
.group(yearGroup)
.x(d3.scaleBand()) //d3.scale.ordinal().domain(genusDim) //d3.scaleBand() for d3 v4
.xUnits(dc.units.ordinal)
.elasticX(true)
.elasticY(true)
.brushOn(false)
.centerBar(true)
// .xAxisLabel('Injury Cause')
.yAxisLabel('Count');
dataCount
.crossfilter(ndx)
.groupAll(all);
d3.selectAll('#all').on('click', function() {
dc.filterAll();
dc.renderAll();
});
d3.selectAll('#Year').on('click', function() {
yearChart.filterAll();
dc.redrawAll();
});
d3.selectAll('#Country').on('click', function() {
CountryChart.filterAll();
dc.redrawAll();
});
d3.selectAll('#WaterType').on('click', function() {
WaterTypeChart.filterAll();
dc.redrawAll();
});
dc.renderAll();
});
单击饼图时的控制台给我以下错误:
cap-mixin.js:187 Uncaught TypeError: Cannot read properties of undefined (reading 'others')
at PieChart.onClick (cap-mixin.js:187:15)
at PieChart._onClick (pie-chart.js:456:18)
at SVGPathElement.<anonymous> (pie-chart.js:163:41)
at SVGPathElement.<anonymous> (d3.js:2248:14)
用于条形图:
Uncaught TypeError: Cannot read properties of undefined (reading 'key')
at utils.js:30:39
at BarChart.onClick (base-mixin.js:1059:42)
at BarChart.onClick (bar-chart.js:272:15)
at SVGRectElement.<anonymous> (bar-chart.js:191:51)
at SVGRectElement.<anonymous> (d3.js:2248:14)
我不确定我是否使用了不再支持的函数图书馆或其他东西。 任何帮助将不胜感激。
I'm currently using d3.js version 7.4.4 and dc.js version 4.0.0.
Here's the code for making a bar chart and 2 pie charts using the same data:
dataCount = dc.dataCount('#data-count');
var CountryChart= new dc.PieChart('#Country');
var WaterTypeChart = new dc.PieChart("#WaterType");
var yearChart = new dc.BarChart("#Year")
d3.csv("file.csv").then(function(data) {
var ndx =crossfilter(data);
var all= ndx.groupAll();
var yearDim= ndx.dimension(function(d){ return d["Year"]});
var CountryDim= ndx.dimension(function(d){ return d["Country"]});
var JournalDim= ndx.dimension(function(d){ return d["Journal"]});
var WaterTypeDim= ndx.dimension(function(d){ return d["WaterType"]});
var CountryGroup = CountryDim.group();
var WaterTypeGroup = WaterTypeDim.group();
var yearGroup= yearDim.group();
CountryChart
.width(220)
.height(200)
.slicesCap(20)
.innerRadius(20)
.dimension(CountryDim)
.group(CountryGroup)
.transitionDuration(500);
WaterTypeChart
.width(220)
.height(200)
.ordinalColors(['#0096FF', '#40E0D0', '#228B22'])
.slicesCap(4)
.innerRadius(10)
.dimension(WaterTypeDim)
.group(WaterTypeGroup);
yearChart
.width(550)
.height(350)
.dimension(yearDim)
.group(yearGroup)
.x(d3.scaleBand()) //d3.scale.ordinal().domain(genusDim) //d3.scaleBand() for d3 v4
.xUnits(dc.units.ordinal)
.elasticX(true)
.elasticY(true)
.brushOn(false)
.centerBar(true)
// .xAxisLabel('Injury Cause')
.yAxisLabel('Count');
dataCount
.crossfilter(ndx)
.groupAll(all);
d3.selectAll('#all').on('click', function() {
dc.filterAll();
dc.renderAll();
});
d3.selectAll('#Year').on('click', function() {
yearChart.filterAll();
dc.redrawAll();
});
d3.selectAll('#Country').on('click', function() {
CountryChart.filterAll();
dc.redrawAll();
});
d3.selectAll('#WaterType').on('click', function() {
WaterTypeChart.filterAll();
dc.redrawAll();
});
dc.renderAll();
});
The console on clicking on the pie chart gives me the following error:
cap-mixin.js:187 Uncaught TypeError: Cannot read properties of undefined (reading 'others')
at PieChart.onClick (cap-mixin.js:187:15)
at PieChart._onClick (pie-chart.js:456:18)
at SVGPathElement.<anonymous> (pie-chart.js:163:41)
at SVGPathElement.<anonymous> (d3.js:2248:14)
For bar charts:
Uncaught TypeError: Cannot read properties of undefined (reading 'key')
at utils.js:30:39
at BarChart.onClick (base-mixin.js:1059:42)
at BarChart.onClick (bar-chart.js:272:15)
at SVGRectElement.<anonymous> (bar-chart.js:191:51)
at SVGRectElement.<anonymous> (d3.js:2248:14)
I'm not sure if I used a function that's no longer supported in the libraries or something else.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论