xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dot Plot with Date Scale and Axis</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
body {
background-color: white;
font-family: Helvetica, Arial, sans-serif;
}
h1 {
font-family:Georgia,serif;
color: #be1258;
font-size: 50px;
font-variant: small-caps; text-transform: none; font-weight: 100; margin-bottom: 0;
}
p {
color: #39677f;
font-size: 10px;
margin: 5px;
font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
font-size: 15px;
}
li {
color: #39677f;
font-size: 10px;
margin: 5px;
font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
font-size: 17px;
}
a {
color: #39677f;
font-size: 10px;
margin: 5px;
font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
font-size: 17px;
}
svg {
background-color: white;
}
circle:hover {
fill: #e41c53;
stroke: white;
}
.axis path {
fill: none;
stroke: grey;
opacity: 0.4
}
.axis line {
fill: none;
stroke: #1d9eBf;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 10px;
}
</style>
</head>
<body>
<h1>Who is leading the wearable health market:
<br>Benefits vs. Uniqueness</br></h1>
<p>Data from Vandrico.com</p>
<br></br>
<li>Y Axis =Benefits-scoring of wearable health device</li>
<li>X Axis =Uniqueness-scoring of wearable health device</li>
<br></br>
Data source: <a href="https://vandrico.com">Vandrico.com</a></p>
<pre>Y Axis =Benefits-scoring of wearable health device</pre>
<script type="text/javascript">
var w = 550;
var h = 700;
var padding = [ 20, 0, 20, 20 ]; //Top, right, bottom, left
var dateFormat = d3.time.format("%Y");
var xScale = d3.time.scale()
.range([ padding[3], w - padding[1] - padding[3] ]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(0)
.tickFormat(function(d) {
return dateFormat(d);
});
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.ticks(0);
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("data2.csv", function(data) {
xScale.domain([
d3.min(data, function(d) {
return dateFormat.parse(d.Uniqueness);
}),
d3.max(data, function(d) {
return dateFormat.parse(d.Uniqueness);
})
]);
yScale.domain([
d3.max(data, function(d) {
return +d.Benefits;
}),
2
]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", function(d) {
return xScale(dateFormat.parse(d.Uniqueness));
})
.attr("cy", function(d) {
return yScale(d.Benefits);
})
.attr("r", 0)
.attr("fill", "#1d9eBf")
.attr("stroke", "#41BEDE")
.append("title")
.text(function(d) {
return d.DeviceName + " :" + d.DeviceDescription;
});
circles.sort(function(a, b) {
return d3.ascending(+a.Uniqueness, +b.Benefits);
})
.transition()
.delay(function(d, i) {
return i * 40;
})
.duration(6000)
.attr("r", 9);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (h - padding[2] + 10) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 10) + ",0)")
.call(yAxis);
});
</script>
<pre> X Axis =Uniqueness-scoring of wearable health device</pre>
<p>Hover over the circles and see the details for each wearable health device Vandrico currently presents on their website</p>
</body>
</html>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js