Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Created November 17, 2017 21:06
Show Gist options
  • Save aaizemberg/b8db69c2051b71bf39e3e104797274b6 to your computer and use it in GitHub Desktop.
Save aaizemberg/b8db69c2051b71bf39e3e104797274b6 to your computer and use it in GitHub Desktop.
BoxPlot (nvd3)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.2/d3.min.js"></script>
<!--
<script src="https://d3js.org/d3.v4.js"></script>
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.min.js"></script>
<style>
text {
font: 12px sans-serif;
}
svg {
display: block;
}
html, body, #chart1, svg {
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div class="gallery" id="chart1">
<svg></svg>
</div>
<script>
nv.addGraph(function() {
var chart = nv.models.boxPlotChart()
.x(function(d) { return d.label })
.staggerLabels(true)
.maxBoxWidth(75) // prevent boxes from being incredibly wide
.yDomain([0, 450]);
d3.select('#chart1 svg')
.data([data])
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
var data = [
{
label: "Sample A",
values: {
Q1: 120,
Q2: 150,
Q3: 200,
whisker_low: 115,
whisker_high: 210,
outliers: [50, 100, 225]
},
},
{
label: "Sample B",
values: {
Q1: 300,
Q2: 350,
Q3: 400,
whisker_low: 225,
whisker_high: 425,
outliers: [175, 450]
},
},
{
label: "Sample C",
values: {
Q1: 50,
Q2: 100,
Q3: 125,
whisker_low: 25,
whisker_high: 175,
outliers: [0]
},
}
];
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment