过滤分组条形图的数据

时间:2015-04-03 09:54:38

标签: d3.js

我正在尝试将我的数据集过滤到一年(1979年),以显示在我的分组条形图中,该条形图基于Mike Bostock的示例。

样品:

1979,Colorectal cancer,20378,19178
1979,Lung cancer,63925,21093
1979,Prostate cancer,6403,43923
1979,Acute myocardial infarction,161723,45470
1979,Cerebrovascular diseases,35719,29415
1979,All stroke,31951,27062
1979,Unintentional injuries,316585,98160
1979,Suicides,89943,27078
1980,Colorectal cancer,20065,18100
1980,Lung cancer,65650,21993
1980,Prostate cancer,6180,43938
1980,Acute myocardial infarction,155525,44623
1980,Cerebrovascular diseases,32367,28014
1980,All stroke,28780,25437
1980,Unintentional injuries,292815,95622
...

在之前的一个实验中,我尝试了一个没有年份的数据集,但工作正常。

Colorectal cancer,20378,19178
Lung cancer,63925,21093
Prostate cancer,6403,43923
Acute myocardial infarction,161723,45470
Cerebrovascular diseases,35719,29415
All stroke,31951,27062
Unintentional injuries,316585,98160
1979,Suicides,89943,27078

似乎使用我的完整数据集添加了Year会导致我的代码出现一些问题,而我似乎无法确定哪些内容已被破坏。如果有人能帮忙,那就太棒了。

链接到jsfiddle:http://jsfiddle.net/vyab4kcf/2/

1 个答案:

答案 0 :(得分:0)

年份密钥是a)所有上层字符和b)字符串。根据以下内容更改过滤器语句:

var yearData = data.filter(function(element) {return element.YEAR == "1979"});

Working fiddle