[Go to site: main page, start]

Most basic boxplot in d3.js





This post describes how to build a very basic boxplot with d3.js. Only one category is represented, to simplify the code as much as possible. You can see many other examples in the boxplot section of the gallery. Learn more about the theory of boxplots in data-to-viz.com.


Boxplot section

Steps:

  • The Html part of the code just creates a div that will be modified by d3 later on.

  • The first part of the javascript code set a svg area. It specify the chart size and its margin. Read more.

  • In this example dummy data are created. It's a vector format. See here to work from a .csv

  • Note that quantiles, median, min and max are computed one by one. See data-to-viz to understand what these values are.

  • The Y scale can now be added. Read here if you're not used to it.

  • Finally, the box can be added, it is just one rect, and 2 lines elements.
<!DOCTYPE html>
<meta charset="utf-8">

<!-- Load d3.js -->


<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>


Related blocks →

  • Simple Box Plot Example in d3.js v4.0 - link

  • D3.js Boxplot with Axes and Labels - link