Search code examples
csvd3.jsfilterparallel-coordinates

Filter Properties Inside Array of Objects to Properly Display Axes in Parallel Coordinate d3


I am creating a parallel coordinate plot from a csv file. There are a few columns in my csv file that I need for other parts of my script (e.g., ID column to join csv to topojson; StateName so that I know which state's data to display).

Here are the properties for each object in my array: CVIRISK, ERR_M_YR, FID, FULLSTATE, GEOM, LENGTH

I can create my parallel coordinate plot properly with the values for each of these properties drawing for every record in my csv.

The problem is that I don't want FID, FULLSTATE or LENGTH to have an axis and show up in my PCP.

I want to create a new array of objects that has all the same objects with specific properties removed.


Solution

  • If source is the array of objects with all the props, and you want picked to be an array of objects with some of those props, you can use Array.prototype.map to instantiate new objects with just the props you care about:

    var picked = source.map(function(d) {
      return {
        CVIRISK:  d.CVIRISK,
        ERR_M_YR: d.ERR_M_YR
      };
    });