Built with blockbuilder.org
forked from romsson's block: Scatterplot Iris using different marks
forked from anonymous's block: Scatterplot Iris using different marks
forked from romsson's block: [introd3] scatterplot using iris dataset
forked from romsson's block: [introd3] scatterplot using iris dataset (template)
forked from romsson's block: [introd3] scatterplot using iris dataset (template)
xxxxxxxxxx
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scaleLinear()
// domain, range
var y = d3.scaleLinear()
//...
var r = d3.scaleSqrt()
//...
var xAxis = d3.axisBottom()
.scale(x);
var yAxis = d3.axisLeft()
.scale(y);
// var color =
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv('iris.csv', function(error, data){
data.forEach(function(d){
// pre-processing
});
// update scales
// x.domain(...
// y.domain(...
// r.domain(...
svg.append('g')
.attr('transform', 'translate(0,' + height + ')')
.attr('class', 'x axis')
.call(xAxis);
svg.append('g')
.attr('transform', 'translate(0,0)')
.attr('class', 'y axis')
.call(yAxis);
// Add axis names
// ...
svg.selectAll("circle").data(d3.range(150)).enter()
.append("circle")
.attr("class", "dot")
.attr("r", 10)
.attr("transform", function(d) {
return "translate(" + (width * Math.random()) + "," + (height * Math.random()) +")";
});
// create legend
var legend = svg.selectAll(".legend")
// .data( ...
// legend.append("rect")
// ...
// legend.append("text")
// ...
});
</script>
Modified http://d3js.org/d3.v4.min.js to a secure url
https://d3js.org/d3.v4.min.js