1

I have a table.

year,continent,state,export_value,import_value,all
2013,Африка,Angola,94061754,220518.54,94282272.54
2013,Африка,Burundi,4136818,1239175.91,5375993.91
2013,Африка,Benin,3251643.49,65421.6,3317065.09

I need to make a pie chart using dc.js:

import/export pie chart

Here is what I tried:

    impexDim            = ndx.dimension(function (d) {return ((d.export_value > 0 ? 'Export' : 'Import') 
                                        && (d.import_value > 0 ? 'Import' : 'Export')) ;}),

    groupeimpexDim      = impexDim.group().reduceSum(function(d) {return +d.all}),

How do I display the columns export_value and import_value as slices of the pie chart?

Gordon
  • 19,811
  • 4
  • 36
  • 74
victor
  • 45
  • 6
  • Possible duplicate of [dc.js - how to create a row chart from multiple columns](http://stackoverflow.com/questions/24737277/dc-js-how-to-create-a-row-chart-from-multiple-columns) – Gordon Feb 09 '17 at 15:45
  • Hello! I believe this is a duplicate of the above linked question, but if you can't figure it out or it doesn't work, please comment and I'll help. As in that question, I don't think you can use this chart to filter others: since every row contributes to both pie slices, there is no way to select rows based on these categories. – Gordon Feb 09 '17 at 15:48
  • Sorry for my English. Thanks for help. But this example doesn't work, when you press the row-chart, pie-chart don't modify. – victor Feb 09 '17 at 17:10
  • Yeah, as I explained above, filtering using this kind of dimension/group doesn't make any sense at all. Crossfilter needs the rows mapped to some keys - so this mapping puts the rows into disjoint sets. Then it filters on the rows. What would you expect filtering on Exports to do? All countries have exports. – Gordon Feb 09 '17 at 17:23
  • Russia's trade with countries of the world, filters across countries and continents – victor Feb 09 '17 at 18:02
  • Sure, it makes sense to filter on country or continent. But how would you filter on Exports? – Gordon Feb 09 '17 at 18:41
  • Exports and imports are filtered by types product, goods and services. – victor Feb 09 '17 at 18:55
  • That's not in this data. Do you mean to filter some other data? – Gordon Feb 09 '17 at 18:56
  • Yes. I now have such dashboards.[link](https://www.dropbox.com/s/qhh0n8mqopx2gqj/dash.png?dl=0) I need show in pie-chart exports and imports balance of trade. – victor Feb 09 '17 at 19:09
  • Sorry, I don't understand. This code in the linked question will let you display imports and exports in the pie chart based on the selected countries and continents in other charts. It won't let you click on exports and imports because there is no way to filter by imports and exports using this data. – Gordon Feb 09 '17 at 19:14
  • Note that in the other example it's the row chart using column-based groups, that's why clicking the row chart does nothing. – Gordon Feb 09 '17 at 19:16
  • Thanks for help, I understand you, we will find another way to solve the problem. – victor Feb 09 '17 at 19:36
  • Glad to hear it. I guess it could trigger a filter on something else (another crossfilter instance, for example) - it's just that there's nothing in_this_ data to filter via imports/exports. – Gordon Feb 09 '17 at 21:42

0 Answers0