JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://square.github.io/cubism/cubism.v1.js"></script>
<div id="demo"></div>
CSS
body{
margin: 0;
}
#demo{
width: 700px;
}
svg {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.axis {
font: 10px sans-serif;
}
.axis text {
-webkit-transition: fill-opacity 250ms linear;
}
.axis path {
display: none;
}
.axis line {
stroke: #000;
shape-rendering: crispEdges;
}
.horizon {
border-bottom: solid 1px #000;
overflow: hidden;
position: relative;
}
.horizon {
border-top: solid 1px #000;
border-bottom: solid 1px #000;
}
.horizon + .horizon {
border-top: none;
}
.horizon canvas {
display: block;
}
.horizon .title, .horizon .value {
bottom: 0;
line-height: 30px;
margin: 0 6px;
position: absolute;
text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
white-space: nowrap;
}
.horizon .title {
left: 0;
}
.horizon .value {
right: 0;
}
.line {
background: #000;
opacity: .2;
z-index: 2;
}
JavaScript
var context = cubism.context()
.step(1e3)
.size(700)
.serverDelay(0)
.clientDelay(0);
function stock(name) {
var value = 0,
values = [],
i = 0,
last;
return context.metric(function(start, stop, step, callback) {
start = +start, stop = +stop;
if (isNaN(last)) last = start;
while (last < stop) {
last += step;
value = 1.3332+0.001 * Math.random();
values.push(value);
}
callback(null, values = values.slice((start - stop) / step));
}, name);
}
var eurusd = stock("EURUSD");
d3.select("#demo").call(function (div) {
div.append("div")
.attr("class", "axis")
.call(context.axis().orient("top"));
div.selectAll(".horizon")
.data([eurusd])
.enter()
.append("div")
.attr("class", "horizon")
.call(context.horizon()
.height(60)
.format(d3.format(".5s"))
);
div.append("div")
.attr("class", "rule")
.call(context.rule());
});
context.on("focus", function (i) {
d3.selectAll(".value").style("right", i == null ? null : context.size() - i + "px");
});