HighChart

Autor Tanmay Dutta

by Sascha

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://rawgit.com/moment/moment/2.2.1/min/moment.min.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Chart showing stacked horizontal bars. This type of visualization is
        great for comparing data that accumulates up to a sum.
    </p>
</figure>

CSS

.highcharts-figure, .highcharts-data-table table {
    min-width: 310px; 
    max-width: 800px;
    margin: 1em auto;
}

#container {
    height: 400px;
}

.highcharts-data-table table {
	font-family: Verdana, sans-serif;
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
	text-align: center;
	width: 100%;
	max-width: 500px;
}
.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}
.highcharts-data-table th {
	font-weight: 600;
    padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
    padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}
.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

JavaScript

var data = [{

     "id": 19,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:01:02.137"
   },
   {
     "id": 20,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:01:02.137"
   },
   {
     "id": 21,
     "name": "x",
     "type": "job",
     "state": "Stop",
     "datetime": "2020-07-14 03:02:02.137"
   },
   {
     "id": 22,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:03:02.137"
   },
   {
     "id": 30,
     "name": "x",
     "type": "job",
     "state": "Stop",
     "datetime": "2020-07-14 03:04:02.137"
   },
   {
     "id": 31,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:05:02.137"
   },
   {
     "id": 32,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:06:02.137"
   },
   {
     "id": 33,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:07:02.137"
   },
   {
     "id": 34,
     "name": "x",
     "type": "job",
     "state": "running",
     "datetime": "2020-07-14 03:08:02.137"
   },
   {
     "id": 35,
     "name": "x",
     "type": "job",
     "state": "stop",
     "datetime": "2020-07-14 03:09:02.137"
   }
 ];
 const today = new Date()
 const yesterday = new Date(today)

 yesterday.setDate(yesterday.getDate() - 1);

 var statusSuccess = [];
 var statusFailure = [];

 data.forEach((element) => {
   if (element.state.toLowerCase() == "running") {
     var datetime = moment(element.datetime).utc().valueOf();

     statusSuccess.push(datetime)
   } else {
     var datetime = moment(element.datetime).utc().valueOf();

     statusFailure.push(datetime)
   }
 });
 
 console.warn(statusSuccess, statusFailure);

 Highcharts.chart('container', {
   chart: {
     type: 'bar'
   },
   title: {
     text: "24 Hrs Status Variation For: " + this.resoucreName
   },
   credits: {
    ...