Skip to main content
100%

Fork of [VizStudy]Week6: Add a menu

✓ Published0🌍 Public
JJerlineJJ
Last edited May 1, 2022
Created on May 1, 2022

This interactive scatter plot visualizes the 2019 World Economic Freedom Index dataset from a GitHub gist. Users can dynamically select which four attributes—teaching, research, citations, and total_score—to display on the x and y axes via React dropdown menus. Built with React hooks (useState), the chart renders SVG circles using D3 v5 scales (scaleLinear) and extent for axis domains. The code includes custom React components for axes and marks, with CSV data loading through D3’s csv function and axis labels updating based on menu selections.

AI-generated description

A scatter plot of The 2019 World Economic Freedom Index dataset.

Data visualization study following Curran.

  1. add dropdown.js to the file which is the same as menus with react

  2. create initial x attributes according to the data columns and add it to the usestate function

    • note that the initial x attributes should be put before the if condition otherwise error occurs.
  3. change the height of the webpage to fit the whole chart. Inspect the menu to see its height, then delete the height from the chart height to render more room for the menue.

  4. Y is completely the same: copy the code creating menu for x for y

  5. make the x axis label and y axis label updated by the selected value

    • move the arributes constant to the front so that it can be used in the following step
    • write getlabel function to get the label based on the selected value
    • change the xaxislabel constant using the getlabel function
  6. Improvements:

    • visually not appealing
    • select attributes not match with the expected scale, not work
MIT Licensed

Similar vizzes