Use D3 in conjunction with javascript and html to create a github pages site with an interactive scatter plot.
In this project, I built an interactive scatterplot to explore the relationships between aggregated census data by state. The final application is hosted on Github Pages at https://joekell.github.io/D3InteractiveScatterPlot/.
The application can be reached at https://joekell.github.io/D3InteractiveScatterPlot/ and is hosted on Github Pages. When opening the dashboard, the x-axis of the scatter plot represents the average age of people in the state and the y-axis represents the percent of people that smoke:
You are then able to scroll down to see detailed notes on using the chart.
These are the tools, techniques, and resources used in this project.
D3 is used in combination with Javascript to generate the interactive plot
HTML is used for the framework of the page
Github Pages is used to host the data and final application
The data is stored in csv format and imported in
This data comes from the US Census.
The first step was to set up locations for the svg area, chart area, plot title, and axes labels. These elements do not change, the labels appear to change in the final application, but that is done with css styles.
In my js file, this function takes up the majority of the space. After static page elements are built, the interactive parts that use the data are required. The appropriate data is then parsed as numbers.
A little bit of math is involved to create the scale for the axes, once these are done, I created groups for each axis and threw them onto the chart area.
First I created a group for each line of data. These groups hold the data and will contain a circle and a text with the state abbreviation.
The circle is added in according to the positioning of the data on the chart.
The text is also added in according to that same positioning. The text is shifted down slightly since the y value determines the top of the text element.
I used D3.Tip() to create the tips, then I called the tip to the circleGroup. Then on mouseover and on mouseout events are added so that the tips are only there when you want them.
When a different label is selected for one of the axes, an on click event is triggered.
The class of the selected label becomes active and the class of the others become inactive.
A new scale is calculated for the selected data set.
The axis tick values are transitioned from old to new.
The position of the circles and text are transitioned from old to new.
The tool tips are updated again.