减少dc.js中的函数
我是dc.js图书馆的新手,想要在我的地理统计图表的组方法中进行下面的crossfilter计算。 我很确定有一些功能可以传递给group
的reduce
方法。
我在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]
以下是我的图表的维度和组:
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
字段的值是使用以下PHP代码计算得出的:
$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;
}
我想要实现的是用dc.js库中的group().reduce(function (p,v) { /* ... */ })
进行相同的计算group().reduce(function (p,v) { /* ... */ })
同时按照分区名称对值进行分组。
你得到什么结果/错误? 看起来非常正确的想法,但要考虑到:
d3.csv()
,它将以字符串的形式返回值,所以您需要预处理数据,或者使用+d.score
在读取数据时转换值 d.SCORE
具体取决于您如何阅读CSV。 如果您在传递的函数中放置换行符,您可以使用浏览器的调试器在那里设置断点,然后在控制台上进行试验以确定哪种表达式适用于您的需要。
链接地址: http://www.djcxy.com/p/32733.html下一篇: dc.js and crossfilter stack bar chart with filtered versus unfiltered