JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="height: 100%"></div>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
function renderItem(params, api) {
let categoryIndex = (params.encode.y[0] - 1) / 2;
let on = api.value('v' + categoryIndex);
if (on !== 1 || on === api.value('v' + categoryIndex, params.dataIndexInside - 1))
return null;
let next = params.dataIndexInside;
while (next < params.dataInsideLength - 1) {
if (api.value('v' + categoryIndex, next + 1) === 0) {
break;
}
next++;
}
let start = api.coord([api.value('c'), categoryIndex]);
let end = api.coord([api.value('e', next), categoryIndex]);
let height = api.size([0, 1])[1] * 0.6;
let rectShape = echarts.graphic.clipRectByRect({
x: Math.floor(start[0]),
y: start[1] - height / 2,
width: Math.ceil(end[0] - start[0]),
height: height
}, {
x: params.coordSys.x,
y: params.coordSys.y,
width: params.coordSys.width,
height: params.coordSys.height
});
return rectShape && {
type: 'rect',
shape: rectShape,
style: api.style()
};
}
option = {
"dataset": {
"dimensions": ["c", "name0", "v0", "name1", "v1", "name2", "v2", "name3", "v3", "e"],
"source": [
[1539238205752, "Water Level", 0, "Pump", 0, "Reservoir", 1, "Too Much", 0, 1539238325508],
[1539238325508, "Water Level", 0, "Pump", 1, "Reservoir", 1, "Too Much", 0, 1539238337191],
...