JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script>
<link rel="stylesheet" href="https://rawgit.com/masayuki0812/c3/master/c3.css">
<div id="chart"></div>
JavaScript
var d = (30 * 24 * 3600); // last 30 days
var array_times = [1414540800, 1414627200, 1414627200 + d, 1414627200 + 2 * d, 1414627200 + 3 * d, ];
var array_values = [67, 66.22, 68, 68, 68];
var labelWeight = 'weight in kg';
var window_period = (30 * 24 * 3600); // last 30 days
var today = Math.floor(new Date(2014, 10, 20, 0, 0, 0, 0).getTime() / 1000);
var timeEnd = today;
var timeStart = today - window_period;
var minT = Math.min.apply(null, array_times),
maxT = Math.max.apply(null, array_times.concat(today));
var minV = Math.min.apply(null, array_values),
maxV = Math.max.apply(null, array_values);
function dateToString(e) {
var date = new Date(e * 1000);
return date.toDateString().substring(4);
}
var chart = c3.generate({
bindto: '#chart',
data: {
x: 'times',
columns: [
['times'].concat(array_times), [labelWeight].concat(array_values)],
labels: {
format: {
y: d3.format('.2')
}
},
type: 'scatter'
},
point: {
r: 6
},
legend: {
show: false
},
grid: {
x: {
show: true
},
y: {
show: true
}
},
axis: {
x: {
label: {
text: 'Time [days]'
},
type: 'timeseries',
tick: {
fit: false,
//count: 29,
rotate: -75,
multiline: false,
format: function (e, d) {
return dateToString(e);
}
},
height: 100
},
y: {
label: {
text: 'Weight [kg]',
position: 'outer',
min: minV - 10,
max: maxV + 10
},
tick: {
format: function (e, d) {
return parseFloat(e).toFixed(2);
}
}
}
...