JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://mbostock.github.com/d3/d3.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var fileName = "data1.csv"
var fileName2 = "data2.csv"
// Set the dimensions of the canvas / graph
var margin = {top: 30, right: 20, bottom: 30, left: 50},
width = 400 - margin.left - margin.right,
height = 250 - margin.top - margin.bottom;
// Parse the date / time
var parseTime = d3.time.format("%d-%m-%Y:%H:%M").parse;
// Set the ranges
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
// Define the axes
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(5);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
// Define the line
var user = d3.svg.line()
.x(function(d) { return x(d.timestamp); })
.y(function(d) { return y(d.user); });
var system = d3.svg.line()
.x(function(d) { return x(d.timestamp); })
.y(function(d) { return y(d.system); });
var funcs = [];
for (var l = 0; l < files.length; l++) {
funcs[l] = function(j) {
window["chart" + j*3] = 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 + ")");
}.bind(this, l);
}
for (var i = 0; i < files.length; i++) {
funcs[i]();
d3.csv(files[i], function(error, data) {
data.forEach(function(d) {
d.timestamp = parseTime(d.timestamp);
d.user = +d.user;
d.system = +d.system;
});
var min = d3.min(data, function(d) { return Math.min(d.user, d.system); });
x.domain(d3.extent(data, function(d) { return d.timestamp; }));
y.domain([min, d3.max(data, function(d) { return Math.max(d.user, d.system); })]);
window["chart" + i*3].append("path")
.data([data])
...