d3使用下拉菜单过滤列标题
我在具有国家/地区列标题的csv中存储数据,并以日期为主要键的行数据的时间序列.
I have data in a csv with countries as columns headers and a timeseries of row data with date as the primary key.
我正在尝试的方法应该很简单,但是我无法使其正常工作. 我有一个包含国家/地区列标题的下拉框.一旦选择了这些,我想参考所选内容以填写图表.
What I am attempting should be fairly straight forward but I haven't been able to get it to work. I have a drop down box which contains the country column headers. Once on of these is selected I want to reference the selection to fill a chart.
如果我明确声明列标题的名称(即如果标题是USA,则它将加载该列的所有数据),则目前可以正常工作.
I currently have this working if I explicitly state the name of the column header i.e if the header is USA which will load all data for that column.
data1.forEach(function(d) {
d.Date = parseDate(d.Date);
d.country= d.USA;
});
但是我需要根据选择的物品而定
But I need this to be based on the item selected which I can get by
var myCountry = this.options[this.selectedIndex].__data__;
我只是想念如何使用此变量来引用d.USA列
I am just missing how to use this variable to reference the column d.USA
好吧,这是我之前尝试过的简单修补程序,Josh提出了建议,但不适用于我的原始代码. jsfiddle.net/enzo267/hK8kG/1
Ok this was a simple fix which I tried previously and Josh suggested but did not work in my original code. jsfiddle.net/enzo267/hK8kG/1