JSFiddle - React, Tailwind, and code Playground

by mjmitche

HTML

<div id="graph">
</div>

<pre id="csvdata">
    zeit,count,total,avg
    5:30,0,0,0
    6:00,14,41.1, $2.94 
    6:30,19,52, $2.74 
    7:00,21,74, $3.52 
    7:30,28,143.25, $5.12 
    8:00,30,141.3, $4.71 
    8:30,32,124.28, $3.88 
    9:00,24,74.8, $3.12 
    9:30,47,172.35, $3.67 
    10:00,27,119.77, $4.44 
    10:30,40,210.44, $5.26 
    11:00,29,150.95, $5.21 
    11:30,14,80.3, $5.74 
</pre>

CSS

/*body { font: 12px Arial;}*/
#csvdata {
    display: none;
}

#vagina{
    font: 12px Arial;
    width:800px;
    height:260px;
}
 
#graph{
    font: 12px Arial;
    width:800px;
    height:260px;
}
path { 
    stroke: steelblue;
    stroke-width: 2;
    fill: none;
}
 
.axis path,
.axis line {
    fill: none;
    stroke: grey;
    stroke-width: 1;
    shape-rendering: crispEdges;
}

JavaScript

(function() {
// Set the dimensions of the canvas / graph
var margin = {top: 30, right: 100, bottom: 30, left: 100},
    width = 800 - margin.left - margin.right,
    height = 270 - margin.top - margin.bottom;
 
// Parse the date / time
var parseDate = d3.time.format("%H:%M").parse,
    formatDate = d3.time.format("%H:%M"),
    bisectDate = d3.bisector(function(d) { return d.zeit; }).left;
 
// 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(12);
 
var yAxis = d3.svg.axis().scale(y)
    .orient("left").ticks(12);
 
// Define the line
var valueline = d3.svg.line()
    .x(function(d) { return x(d.zeit); })
    .y(function(d) { return y(d.count); });
    
// Adds the svg canvas
var svg = d3.select("#graph")
    .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 + ")");
 
var lineSvg = svg.append("g"); 
 
var focus = svg.append("g") 
    .style("display", "none");
 
// Get the data
var raw = d3.select("#csvdata").text();
var data = d3.csv.parse(raw);

    data.forEach(function(d) {
         // console.log("data in raw", d);
        d.zeit = parseDate(d.zeit);
        d.total = +d.total;
        d.count = d.count;
    });
 
    // Scale the range of the data
    x.domain(d3.extent(data, function(d) { return d.zeit; }));
    y.domain([0, d3.max(data, function(d) { return d.count; })]);
 
    // Add the valueline path.
    lineSvg.append("path")
        .attr("class", "line")
        .attr("d", valueline(data));
 
    // Add the X Axis
    svg.append("g")
        .attr("class", "x axis")
        .attr("transform", "translate(0," + height + ")")
        .call(xAxis);
 
    // Add the Y Axis
    svg.append("g")
        .attr("class", "y axis")
     ...