我是dc.js库的新手,想在我的geochoropleth图表的group方法下进行crossfilter计算。我很确定我可以将一些函数传递给reduce
的{{1}}方法。
我在group
中有以下数据(第一行包含列名):
DATA.csv
以下是我的图表的尺寸和组:
BUDGET,GID,MDIS,USPRO,TYPE,FILEURL,RVID,VERDATE,VERSTAT,SCORE
10428,ALI-G-006,Aliabad,Kunduz,Hard,/uploadedfiles/reports/SIKA North/136-SIKA-North-ALI-G-006.pdf,0,19-08-2014,2,0
24853,ALI-G-008,Aliabad,Kunduz,Hard,/uploadedfiles/reports/SIKA North/561-SIKA-North-ALI-G-008.pdf,0,19-08-2014,0
24831,ALI-G-019,Aliabad,Kunduz,Hard,/uploadedfiles/reports/SIKA North/987-SIKA-North-ALI-G-019.pdf,0,18-08-2014,2,0
24771,IMA-G-017,Imam Sahib,Kunduz,Hard,/uploadedfiles/reports/SIKA North/557-SIKA-North- IMA-G-017.pdf,0,28-08-2014,2,1
21818,IMA-G-019,Imam Sahib,Kunduz,Hard,/uploadedfiles/reports/SIKA North/992-SIKA-North-IMA-G-019.pdf,0,27-08-2014,2,0
12266,KHA-G-007,Khanabad,Kunduz,Hard,/uploadedfiles/reports/SIKA North/583-SIKA-North - KHA-G-007.pdf,0,7/9/2014,1,0
23148,KUN-G-002,Kunduz,Kunduz,Hard,/uploadedfiles/reports/SIKA North/909-SIKA-North - KUN-G-002.pdf,0,1/9/2014,2,0
54584,KUN-G-004,Kunduz,Kunduz,Hard,/uploadedfiles/reports/SIKA North/702-SIKA-North - KUN-G-004 20140709.pdf,0,9/7/2014,1,0
24544,PUL-G-001,Pul-e Khumri,Baghlan,Hard,/uploadedfiles/reports/SIKA North/599-SIKA-North - PUL-G-001 - 20140623.pdf,0,6/7/2014,2,1
40149,SSKDAG046,Arghandab (1),Kandahar,Hard,/uploadedfiles/reports/SIKA South/239-SIKA-South-SSKDAG046.pdf,0,12/9/2014,0,0.625
39452,0003 LGR MAG,Muhammad Aghah,Logar,Hard,/uploadedfiles/reports/SIKA East/792-SIKA-East - 0003 LGR MAG - 20140610.pdf,0,10/6/2014,2,0.7
58298,0013 LGR MAG,Muhammad Aghah,Logar,Hard,/uploadedfiles/reports/SIKA East/591-SIKA-East - 0013 LGR MAG 20140601.pdf,0,1/6/2014,2,0]
使用以下代码使用PHP计算var facts = crossfilter(data);
var scoref = facts.dimension(function (d) { return d.district;});
var scoreg = scoref.group().reduceSum(function(d){return d.score;});
字段的值:
d.score
我想要实现的是使用来自dc.js库的$tempsql = $dbase->query('select "VERMDIS", COUNT(*) AS TOTAL, SUM("VERSTAT") AS SAM FROM mt_fver GROUP BY "VERMDIS"');
while ($r = pg_fetch_array($tempsql)) {
$dist = $r['VERMDIS'];
$score = $r[2] / (2 * $r[1]);
$disxx[$dist] = $score;
}
进行相同的计算,同时按地区名称对值进行分组。
答案 0 :(得分:1)
您得到的结果/错误是什么?看起来几乎是正确的想法,但考虑到:
d3.csv()
,则会将值作为字符串返回,因此您需要预先处理数据,或者在阅读时使用+d.score
转换值它们d.SCORE
,具体取决于您如何阅读CSV。如果你在传递给reduce的函数中放置一个换行符,你可以使用浏览器的调试器在那里设置一个断点,并在控制台上进行实验,找出你需要的表达式。