Iman
Iman

Reputation: 483

How to set predefined ordinal values for parallel coordinates in D3.js?

I want to know how to set predefined ordinal values for parallel coordinates?

For example (here) if we remove the car with "blue" value, the D3 remove the blue label for us, but I want define my set of labels first (blue,red,green) and then D3 show blue label without connection (if I remove the blue car).

{"name": "AMC Concord DL 6", "weight (lb)":3265, "0-60 mph (s)": 18.2, "year": 79, "colour": "blue"}

Upvotes: 0

Views: 59

Answers (1)

meetamit
meetamit

Reputation: 25157

Currently, you're setting the domain (i.e. all the possible colour values) like this:

y[d] = d3.scale.ordinal()
  .domain(cars.map(function(p) { return p[d]; }))

So, inherently, if cars doesn't contain a blue car, that value doesn't make it into the domain.

Since you're asking for the colour value to be there even if it's not in cars, I presume you're ok hard-coding the domain's values (because otherwise there's no way for "blue" to make it into the dataset/domain). So, to hard code, replace the .domain() call above with:

y[d] = d3.scale.ordinal()
  .domain(['blue', 'green', 'red'])

See updated jsFiddle.

Upvotes: 1

Related Questions