Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stacked bar chart #22

Open
7marjorie opened this issue Jan 24, 2017 · 4 comments
Open

stacked bar chart #22

7marjorie opened this issue Jan 24, 2017 · 4 comments

Comments

@7marjorie
Copy link

Hey Curran,

Thanks for the sreencasts, I was very helpful.
I made the stacked bar chart and it works ok, if there is no missing data.
In your csv file" religionByCountryTop5.csv" for example Brazil Hindu is marked zero.
In my case the combination of Brazil Hindu would not be in the file.
How can adjust the code to work if data is missing, I plug the chart on oracle BI, so I don't know in advance if data is going to be missing.

Thanks,

@curran
Copy link
Owner

curran commented Jan 25, 2017

Hi @7marjorie ,

If the data is missing, would you like to treat that as a zero value? If so, probably the best approach would be to detect which pairs are missing, and add "fake data" that fills them in as zero values, before passing the data into d3.nest.

I think the problem is that stack() expects clean data where all possible pairs are filled in. Probably one way to sol you could do is not use d3.nest(), but instead roll your own nested loop that iterates over all combinations (the cartesian product of domains for the two fields), looks them up in the actual data, and generates a zero value for pairs that are not in the original data.

These answers might also be helpful:

Also, this would be a great question for the D3 mailing list, perhaps someone there has a better answer.

@7marjorie
Copy link
Author

7marjorie commented Jan 31, 2017 via email

@curran
Copy link
Owner

curran commented Jan 31, 2017

@7marjorie No problem! I feel like it's a common problem, and it would be interesting to have a library that does the filling in of the gaps based on the cartesian product.

You might also want to try Datalib https://github.com/vega/datalib/wiki/API-Reference#group-by-aggregation . They have a nice group-by aggregation feature. Although your data is already aggregated, I wonder if you pass it through their group-by processing if it might add in the zeros.

@7marjorie
Copy link
Author

7marjorie commented Jan 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants