JSFiddle - React, Tailwind, and code Playground
by Andrew
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="bar-chart" width="600" height="350"></canvas>
<canvas id="bar-chart-middle" width="600" height="350"></canvas>
CSS
canvas {
max-width: 600px;
min-width: 600px;
max-height: 300px;
min-height: 300px;
margin-top: 20px;
margin-left: 40px;
}
body {
background: white;
}
JavaScript
var superLineTo;
superLineTo = Chart.helpers.canvas.lineTo;
Chart.helpers.canvas.lineTo = function(ctx, previous, target, flip) {
var xInTheMiddle;
if (target.steppedLine === 'middle') {
xInTheMiddle = previous.x + (target.x - previous.x) / 2;
ctx.lineTo(xInTheMiddle, previous.y);
ctx.lineTo(xInTheMiddle, target.y);
ctx.lineTo(target.x, target.y);
return;
}
return superLineTo(ctx, previous, target, flip);
};
var options = {
"type": "bar",
"data": {
"labels": [
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34
],
"datasets": [
{
"type": "line",
"data": [
8,
12,
15,
10,
5,
6,
4,
25,
30,
30,
20,
20,
10,
10,
20,
10
],
"borderColor": "rgba(200,200,200,0.5)",
"label": "TRUE",
"yAxisID": "no-stacked",
"backgroundColor": "rgba(0,0,0,0)",
"steppedLine": true,
"borderWidth": 1,
"pointRadius": 0
},
{
"type": "bar",
"data": [
5,
10,
1,
3,
5,
5,
5,
14,
20,
10,
8,
10,
4,
10,
19,
3
],
"backgroundColor": "rgb(19, 107, 252)",
"label": "BARS",
"yAxisID": "stacked",
"hoverBackgroundColor": "rgb(19, 107, 252)"
}
]
},
"options": {
"maintainAspectRatio": false,
"scales": {
"xAxes": [
{
"gridLines": {
"color": "rgba(0,0,0,0)"
},
"stacked": true,
"categoryPercentage": 0.6,
"ticks": {
"autoSkip": true,
"maxTicksLimit": 50
}
}
...