4

The xaxis on our Distinct Bar Chart is user names. The problem I have is that there can be multiple users with the same name.

I want the x-axis to be distinct by the user's id but would like the label to be the user's name (Yeah, I understand that the name is ambiguous, but that is OK for our purposes)

Given the following data how would I get the x-axis to be distinct by id but display the label value

[{
    "key" : "tester",
    "values" : [{
        "value" : 5.0,
        "label" : "John Smith",
        "color" : "#9BA474",
        "id" : 1388
    }, {
        "value" : 10.25,
        "label" : "Jane D'oh",
        "color" : "#356AA0",
        "id" : 11
    }, {
        "value" : 3.5,
        "label" : "John Smith",
        "color" : "red",
        "id" : 12
    }]
}]
4

1 回答 1

2

我可能对我自己的问题有答案。如果有其他方法可以做到这一点,我想听听。

var chart = nv.models.discreteBarChart()
        .x(function(d, i) { return i })
        .y(function(d) { return d.value });

chart.xAxis
        .tickFormat(function(d) {return data[0].values[d].label; });
于 2013-08-20T10:41:35.683 回答