如何解决DC.JS OnClick函数的控制台误差?

发布于 2025-02-09 10:35:56 字数 2755 浏览 1 评论 0原文

我目前正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文