JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.js"></script>
<div id="showChart">
<p>SEE PROGRESS</p>
</div>
<div id="containChart">
<canvas id="theChart" width="300" height="300"></canvas>
<div id="closeChart">CLOSE</div>
</div>
CSS
#containChart
{
display: none; /* Change to block and problem goes away */
position: fixed;
top: 2px;
left: 2px;
width: 500px;
height: 400px;
background-color: #f2f2f2;
}
#theChart
{
position: absolute;
top: 10px;
}
JavaScript
// Fetch date via moment.js
function newDate(days)
{
return moment().add(days, 'd');
};
var config =
{
type: 'line',
data:
{
// Use fetched date to track progress over time.
labels: [newDate(-4), newDate(-3), newDate(2), newDate(3), newDate(4), newDate(5), newDate(6)],
// Feed data to chart.
datasets:
[{
label: "Strength",
data: [2, 3, 4, 2, 1, 4],
backgroundColor: 'rgba(0, 0, 255, 0)',
borderColor: 'rgba(0, 0, 255, 1)',
borderWidth: 1.5
},
{
label: "Cardio",
data: [1, 3, 2, 3, 3],
backgroundColor: 'rgba(255, 0, 0, 0)',
borderColor: 'rgba(200, 0, 0, 1)',
borderWidth: 1.5
}]
},
// Configure axis.
options:
{
chartArea:
{
backgroundColor: '#ffffff',
},
layout:
{
padding:
{
left: 20,
right: 0,
top: 0,
bottom: 0
}
},
scales:
{
xAxes:
[{
ticks:
{
suggestedMax: 4,
suggestedMin: 4,
stepSize: 1
},
type: 'time',
time:
{
unit: 'week',
//unitStepSize: 1
displayFormats:
{
'hour': 'MMM DD',
'day': 'MMM DD',
'week': 'MMM DD',
'month': 'MMM DD',
'year': 'MMM DD'
}
}
}],
yAxes:
[{
ticks:
{
max: 4,
min: 0,
stepSize: 1
}
}]
},
}
};
// Create chart with previously determined configurations.
var ctx = document.getElementById("theChart").getContext("2d");
var chart = new Chart(ctx, config);
Chart.defaults.global.defaultFontColor = "#58a7dd";
Chart.defaults.global.defaultFontSize = "10";
// Show...