JSFiddle - React, Tailwind, and code Playground
by Chinmay Pendharkar
HTML
<script src="http://d3js.org/d3.v3.js"></script>
<h1><center> Welcome to Emosis!</center> </h1>
<br>
<h3>Choose your Patient: </h3>
<br>
<select id="Patients" onchange="updateData()">
<option value=0>Choose Patient</option>
<option value=1>Patient 1: 24/06/2014 13:11</option>
<option value=2>Patient 2: 24/06/2014 15:52</option>
<option value=3>Patient 3: 25/05/2014 11:20</option>
</select>
<br>
<center>
<button onclick="fftdata()">View frequency domain</button>
</center>
<center>
<button onclick="timedata()">View time domain</button>
</center>
CSS
body {
font: 10px sans-serif;
}
.chart {
margin: auto;
width: 70%;
}
.graph {
margin: auto;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
.line {
fill: none;
stroke: firebrick;
stroke-width: 1.5px;
}
.line2 {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
.grid .tick {
stroke: lightgrey;
opacity: 0.7;
}
.grid path {
stroke-width: 0;
}
JavaScript
var margin = {
top: 200,
right: 0,
bottom: 30,
left: 100
},
width = 550 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var parseDate = d3.time.format("%d-%b-%y").parse; //need to change later
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
var xAxis = d3.svg.axis().scale(x)
.orient("bottom")
.ticks(6);
var yAxis = d3.svg.axis().scale(y)
.orient("left")
.ticks(5);
var line = d3.svg.line()
// .interpolate("basis")
.x(function (d) {
return x(d.date);
})
.y(function (d) {
return y(d.close);
});
var line2 = d3.svg.line()
.x(function (d) {
return x(d.date);
})
.y(function (d) {
return y(d.close);
});
var chart = d3.select("body").append("div")
.attr("class", "chart");
//create the canvas to draw on.
var svg = chart.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.attr("class", "graph")
.append("g") //grouping element
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
//creating second canvas to draw on
var svg2 = chart.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.attr("class", "graph")
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
//get the data through request function
d3.csv("http://128.199.248.15/datasho1.csv", function (error, data) {
data.forEach(function (d) {
d.date = parseDate(d.date);
d.close = +d.close;
});
//scale data range
x.domain(d3.extent(data, function (d) {
return d.date;
}));
y.domain(d3.extent(data, function (d) {
return d.close;
}));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
...