Column chart with data labels
author(s):
Øystein Moseng
by oysteinmoseng
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.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://code.highcharts.com/themes/high-contrast-light.js"></script>
<h1>Column chart with data labels</h1>
<h2>Chart</h2>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Vertical column chart with data labels.
</p>
</figure>
<h2>CSV data</h2>
<p>
Source: <a href="https://data.world/mini-mia/2014-berlin-marathon-stats">data.world</a>.
</p>
<pre id="csv">Country,Participants
Germany,11289
Denmark,2612
United Kingdom,2109
France,1303
Netherlands,990
Italy,902
United States,836
Sweden,831
Spain,788
Poland,740
Switzerland,652
Norway,470
Austria,469</pre>
CSS
body {
font-family: Verdana, sans-serif;
padding-left: 10px;
}
h2 {
font-size: 1.3rem;
margin-left: 10px;
margin-bottom: 0;
margin-top: 1.5rem;
}
p {
margin-left: 1rem;
}
pre {
margin-left: 1rem;
border: 1px solid #cde;
max-width: 600px;
padding: 10px;
background-color: #f9f9f9;
border-radius: 10px;
}
#container {
height: 400px;
}
.highcharts-figure, .highcharts-data-table table {
min-width: 320px;
max-width: 600px;
margin: 1em;
}
.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;
}
input[type="number"] {
min-width: 50px;
}
JavaScript
// Configure the visualization
var chart = Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Participants in 2014 Berlin Marathon by Country'
},
legend: {
enabled: false
},
subtitle: {
text: 'Source: <a href="https://data.world/mini-mia/2014-berlin-marathon-stats">data.world</a>'
},
tooltip: {
backgroundColor: 'rgba(255, 255, 255, 0.9)',
stickOnContact: true
},
yAxis: {
title: {
text: ''
}
},
xAxis: {
labels: {
style: {
color: '#444'
}
}
},
data: {
csv: document.getElementById('csv').innerHTML
},
plotOptions: {
column: {
dataLabels: {
enabled: true
}
}
}
});