Home Update JavaScript tutorial: Beyond primary charts with React-vis

JavaScript tutorial: Beyond primary charts with React-vis

257


Last week we took a primary have a look at React-vis, the open-source charting library, and constructed up our first bar chart utilizing the City of New York Popular Baby Names information set. This week, we’ll develop on our preliminary instance and present how we are able to start to include primary interactions. As a refresher, our information set consists of rows of knowledge that appear like this:

{
  "Year of Birth": "2016",
  "Gender": "FEMALE",
  "Ethnicity": "ASIAN AND PACIFIC ISLANDER",
  "Child's First Name": "Olivia",
  "Count": "172",
  "Rank": "1"
}

The first visualization we constructed was a bar chart that confirmed the overall variety of youngsters’s names accounted for within the information by 12 months, which regarded like this:

react vis fig03IDG

For our subsequent visualization, let’s see if we are able to map the recognition of a reputation over time. To begin off, we’ll construct a easy line chart utilizing the LineMarkSeries element. In order to get the recognition of the identify Olivia over time, we are able to use the identical filtering logic we used to get yearly totals if we add a filtering step forward of time:

    const oliviaData = information.filter(d => d.firstName === 'Olivia');
    const oliviasByYear = Object.entries(oliviaData.cut back((acc, row) => {
      if(row.yearOfBirth in acc) {
        acc[row.yearOfBirth] = acc[row.yearOfBirth] + row.depend
      } else {
        acc[row.yearOfBirth] = row.depend
      }
      return acc;
    }, {})).map(([k, v]) => ({x: +okay, y: v}));



Source hyperlink

LEAVE A REPLY

Please enter your comment!
Please enter your name here