1

I have JSON data like following:

[{
    "clin_p_id": 'A9VV',
    'patient.drugs.drug': [
        'Carboplatin',
        'Alimta'
    ]
},
{
    "clin_p_id": "A9VP",
    "patient.drugs.drug": [
        "Carboplatin",
        "Alimta"
    ]
}]

how do I create a pie chart that shows all the patients who take certain drug?

This is what I have so far:

var grp = dims['patient.drugs.drug'].group().reduce(
    function (p, v) {
        if (v[id_col] in p.patients) {
            p.patients[v['clin_p_id']]++;
        }
        else {
            p.patients[v['clin_p_id']] = 1;
            p.patientCount++;
        }
        return p;
    },
    function (p, v) {

        p.patients[v['clin_p_id']]--;
        if (p.patients[v['clin_p_id']] === 0) {
            delete p.patients[v['clin_p_id']];
            p.patientCount--;
        }
        return p;
    },
    function () {
        return {
            patientCount: 0,
            patients: {}
        };
    }
);

But this wouldn't work if I want to count individual drug name.

Waleed Iqbal
  • 1,308
  • 19
  • 35
Anney Che
  • 97
  • 3
  • I think this is what the [`isArray` parameter of `.dimension()`](https://github.com/crossfilter/crossfilter/wiki/API-Reference#dimension) does, in the community fork of crossfilter. – Gordon Nov 23 '16 at 04:39
  • There's also this old Q&A: http://stackoverflow.com/questions/17524627/is-there-a-way-to-tell-crossfilter-to-treat-elements-of-array-as-separate-record – Gordon Nov 23 '16 at 04:40
  • @Gordon - Yup, that's exactly what it does. I'd highly recommend using this. It'll be a lot faster than custom reducers. My assumption is that you are created your dimension on `clin_p_id`. – Ethan Jewett Nov 24 '16 at 16:57
  • @Gordon - isArray seems not working for me. Could you post an example of dimension with arrays? my pie chart is still using the arrays as the key. – Anney Che Nov 28 '16 at 14:18

0 Answers0