Search code examples
data-visualizationdimple.js

dimple.js aggregating non-numerical values


Say i have a csv containing exactly one column Name, here's the first few values:

Name
A
B
B
C
C
C
D

Now i wish to create a bar plot using dimple.js that displays the distribution of the Name (i.e the count of each distinct Name) but i can't find a way to do that in dimple without having the actual counts of each name. I looked up the documentation of chart.addMeasureAxis( https://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#addMeasureAxis) and found that for the measure argument:

measure (Required): This should be a field name from the data. If the field contains numerical values they will be aggregated, if it contains any non-numeric values the distinct count of values will be used.

So basically what that says is it doesn't matter how many times each category occurred, dimple is just going to treat each of them as if they occurred once ??

I tried the following chart.addMeasureAxis('y', 'Name') and the result was a barplot that had each bar at value of 1 (i.e each name occurred only once).

Is there a way to achieve this without changing the data set ?


Solution

  • You do need something else in your data which distinguishes the rows:

    e.g.

    Type    Name
    X       A
    Y       A
    Z       A
    X       B
    Y       B
    A       C
    

    You could do it with:

    chart.addCategoryAxis("x", "Name");
    chart.addMeasureAxis("y", "Type");
    

    or add a count in:

    Name    Count
    A       1
    A       1
    A       1
    B       1
    B       1
    C       1
    

    Then it's just

    chart.addCategoryAxis("x", "Name");
    chart.addMeasureAxis("y", "Count");
    

    But there isn't a way to do it with just the name.