Area Chart using React.js d3.js & TypeScript with the help of d3-brush for interaction
To create brush interactivity of the mouse following the plotted data there is d3 has an API d3-brush
that can help us. In this tutorial, I will show you how to work with thed3-brush
to zoom into a specific date.
You can see the final result of this tutorial below;
Setting up your project
I will be using CRA (SPA) using the MHL template to get TS, SCSS, formatting, templates, linting, etc.
$ yarn create react-app area-brush --template must-have-libraries
Add d3, d3-cloud and types;
$ yarn add d3 @types/d3
area.csv
A good place to start when working with charts is from the data. The data is made out of two metrics: date, value values.
/public/data/area.csv
date,value
2007-04-23,93.24
2007-04-24,95.35
2007-04-25,98.84
2007-04-26,99.92
2007-04-29,99.8
2007-05-01,99.47
...
To creating the components we will be using my templates to speed up development;
$ npx generate-react-cli component Brush --type=d3WidgetComponent$ npx generate-react-cli component ChartWidget --type=d3Widget