Basic line
author(s):
Torstein Hønsi
by oysteinmoseng
May 20, 2022
HTML
<script src="https://code.highcharts.com/9/highcharts.js"></script>
<script src="https://code.highcharts.com/9/modules/series-label.js"></script>
<script src="https://code.highcharts.com/9/modules/exporting.js"></script>
<script src="https://code.highcharts.com/9/modules/export-data.js"></script>
<script src="https://code.highcharts.com/9/modules/accessibility.js"></script>
<input value="click to focus">
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Basic line chart showing trends in a dataset. This chart includes the
<code>series-label</code> module, which adds a label to each line for
enhanced readability.
</p>
</figure>
CSS
.custom-tooltip {
background-color: rgba(255, 255, 255, 0.8);
color: #000;
border: 1px solid #999;
font-size: 13px;
padding: 5px;
font-family: sans-serif;
}
.highcharts-figure,
.highcharts-data-table table {
min-width: 360px;
max-width: 800px;
margin: 1em auto;
}
.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
Highcharts.addEvent(Highcharts.Chart, 'render', function () {
const menuComponent = this.accessibility.components.chartMenu;
const proxy = menuComponent.exportButtonProxy.buttonElement;
if (proxy && !proxy.hasCustomTooltip) {
const tooltip = document.createElement('div');
tooltip.style.display = 'none';
tooltip.style.position = 'absolute';
tooltip.setAttribute('aria-hidden', true);
tooltip.style.left = parseFloat(proxy.style.left) - 50 + 'px';
tooltip.style.top = parseFloat(proxy.style.top) + 30 + 'px';
tooltip.textContent = 'Chart menu';
tooltip.className = 'custom-tooltip';
menuComponent.proxyProvider.groups.chartMenu.groupElement.appendChild(tooltip);
proxy.hasCustomTooltip = true;
proxy.addEventListener('focus', function () {
tooltip.style.display = 'block';
});
proxy.addEventListener('blur', function () {
tooltip.style.display = 'none';
});
}
});
Highcharts.chart('container', {
title: {
text: 'Solar Employment Growth by Sector, 2010-2016'
},
subtitle: {
text: 'Source: thesolarfoundation.com'
},
yAxis: {
title: {
text: 'Number of Employees'
}
},
xAxis: {
accessibility: {
rangeDescription: 'Range: 2010 to 2017'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 2010
}
},
series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}, {
name: 'Manufacturing',
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
}, {
name: 'Sales & Distribution',
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
}, {
name:...