Highcharts Demo
by maritavindedal
February 10, 2025
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/pattern-fill.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
This bar chart compares the estimated production of corn and wheat for 2023 across six countries:
the USA, China, Brazil, the EU, Argentina, and India. Corn production significantly exceeds wheat production
in countries like the USA and Brazil, while wheat production surpasses corn in the EU. The chart uses metric tons
(MT) as the unit and highlights data sourced from IndexMundi.
</p>
</figure>
CSS
#container {
max-width: 800px;
margin: 1em auto;
}
#pref-menu-dialog {
z-index: 9999;
background-color: white;
padding: 20px;
border: 1px solid black;
border-radius: 5px;
min-width: 320px;
}
.pref {
display: flex;
align-items: center;
gap: 10px;
}
h3 {
margin-bottom: 10px;
}
/* To avoid screen reader region disappearing after chart.update() */
.hide-section {
position: static !important;
width: auto !important;
height: auto !important;
overflow: visible !important;
white-space: normal !important;
clip: auto !important;
margin-top: 0 !important;
opacity: 1 !important;
}
.highcharts-button-normal:hover,
.highcharts-button-normal-hover {
cursor: pointer;
}
#small-font {
font-size: 10px !important;
}
#default-font {
font-size: 16px !important;
}
#large-font {
font-size: 22px !important;
}
.alt-text-div {
position: absolute;
padding: 4px;
font-size: 12px;
transform: translate(-50%, -100%);
pointer-events: none;
}
#hc-pref-button-fallback text {
font-size: 1.2em !important;
}
#hc-pref-button-fallback rect {
fill: rgb(255, 255, 255) !important;
stroke: rgb(255, 255, 255) !important;
}
.hc-pref-button-bg {
fill: white !important;
stroke-width: 1px;
transition: fill 0.2s ease;
pointer-events: all;
}
.hc-pref-button:hover .hc-pref-button-bg {
fill: rgb(211, 211, 211) !important;
}
.alt-text-div {
max-width: 50px;
border: 1px solid black;
border-radius: 2px;
opacity: 1;
background: #fff;
}
JavaScript
// Colors for light theme
const defaultColorsLight = ['#90D2FE', '#ffb8b8'],
contrastColorsLight = ['#247eb3', '#dd3636'],
borderColorsLight = contrastColorsLight,
borderColorsWithContrastLight = ['#103042', '#561515'];
// Colors for dark theme
const defaultColorsDark = ['#015288', '#A80000'],
contrastColorsDark = ['#16A0FD', '#FE6264'],
borderColorsDark = contrastColorsDark,
borderColorsWithContrastDark = ['#FFFFFF', '#FFFFFF'];
// Defining description formats for verbosity
const shortPointDescriptionFormat =
'{point.category}, {(point.y):,.0f} (1000 MT).';
const fullPointDescriptionFormat = 'Bar {add index 1} of ' +
'{point.series.points.length} in series {point.category}, ' +
'{point.series.name}: {(point.y):,.0f} (1000 MT).';
let longDesc = '';
let shortDesc = '';
const lightTheme = {
colors: defaultColorsLight,
contrastColors: contrastColorsLight,
borderColors: borderColorsLight,
borderColorsWithContrast: borderColorsWithContrastLight,
chart: {
backgroundColor: '#ffffff',
style: {
color: '#000000'
}
},
title: {
style: {
color: '#000000'
}
},
subtitle: {
style: {
color: '#000000'
}
},
yAxis: {
labels: {
style: {
color: '#000000'
}
},
title: {
style: {
color: '#000000'
}
}
},
xAxis: {
labels: {
style: {
color: '#000000'
}
}
},
legend: {
itemStyle: {
color: '#000000'
}
},
credits: {
style: {
color: '#000000'
}
},
tooltip: {
backgroundColor: '#ffffff',
style: {
color: '#000000'
}
},
outsideChart: {
backgroundColor: '#ffffff',
textColor: '#000000'
},
button: {
...