Basic column

author(s): Torstein Hønsi

by harifrais

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>

<figure class="highcharts-figure">
    <div id="container"></div>
   
</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 = [{"project":"Sciera Internal Application","hours":{"APPLICATIONS DEVELOPMENT":33325,"DATA MANAGEMENT AND OPERATION":328095}},{"project":"SKY","hours":{"DATA MANAGEMENT AND OPERATION":563250}},{"project":"RealWatch","hours":{"DATA MANAGEMENT AND OPERATION":71175,"APPLICATIONS DEVELOPMENT":3015}},{"project":"Cox data aggregation","hours":{"APPLICATIONS DEVELOPMENT":58265}},{"project":"Sciera Web Application","hours":{"APPLICATIONS DEVELOPMENT":72720}},{"project":"C-TELL","hours":{"DATA MANAGEMENT AND OPERATION":488470}},{"project":"Aroscop","hours":{"APPLICATIONS DEVELOPMENT":99160}},{"project":"Pulz","hours":{"APPLICATIONS DEVELOPMENT":3940}},{"project":"Timesheet","hours":{"APPLICATIONS DEVELOPMENT":137215}}]

var result = data.reduce( (acc, {hours}) => {
    Object.keys(hours).forEach(key => {
        if(!acc[key]) acc[key] = [];
        
        acc[key].push(hours[key]);
    })
    return acc;
},{});

var seriesData = Object.entries(result).map(e => ({
   name: e[0],
   data: e[1]
}));

console.log(seriesData);

var categoriesData = data.map( ({project}) => project);

console.log(categoriesData);


Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Work Efficiency Report'
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        categories:categoriesData,
        crosshair: true
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Hours Worked'
        }
    },
    tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },
    plotOptions: {
        column: {
            pointPadding: 0.2,
            borderWidth: 0
        }
    },
    series:seriesData
});