当前位置: 动力学知识库 > 问答 > 编程问答 >

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"}

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: