Grouped bar chart displaying cross tab between groups

℡╲_俬逩灬. 提交于 2019-12-24 12:27:43

问题


I'm trying to make a group bar chart that gives the frequency of two group combos. I referred to this site for rollup and nest function reference: http://bl.ocks.org/phoebebright/raw/3176159/

I'm trying to use my own dataset to create the following effect: https://bl.ocks.org/bricedev/0d95074b6d83a77dc3ad

My current attempt with my own data, drug1.csv: https://blockbuilder.org/lydiawawa/9efb5df76c08640316efbef702437db7

In the console, the grouped counts do not seem to generate the right distributions. Something is wrong with my rollup and nest

  const nestedData = d3.nest()
    .key(function(d){return d.s_category})
    .key(function(d){return d.drug_cat})
    .rollup(function(leaves) { return leaves.length; })
    .entries(data);

Following is the desired cross tab distribution count of s_category x drug_cat :

      1   2   3   4   5   6
  2 367  35   8   1   1   1
  3 223  24   4   4   2   2
  4  29   5   9   1   2   3
  5  37   1   3   3   2  26

Static chart:

In the animated bar graph that I attempted to create, cross tab count should be the y-axis, drug_c is the x-axis and s_category determines the groups of the bar graph. Thank you for any help!


回答1:


The moment you use the nest generator you don't have drug_cat and count as properties anymore: you have key and values (or value for the inner arrays).

Here is your block builder changing the names of those properties: https://blockbuilder.org/GerardoFurtado/f4c825a5f8c92e87cc5a81591ba1f7c9



来源:https://stackoverflow.com/questions/55786238/grouped-bar-chart-displaying-cross-tab-between-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!