Highcharts Responsive Flex
by incutonez
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>
<div class="flex h-full">
<article class="flex flex-2">
<section class="flex flex-1 flex-col">
<span>This is the Title</span>
<div id="container" class="flex-1"></div>
</section>
<section class="container2 flex flex-1 flex-col">
<span>This is the 2nd Title</span>
<div id="container2" class="flex-1"></div>
</section>
</article>
<div class="flex-1">
<div id="container3" class="flex-1"></div>
</div>
</div>
CSS
.flex {
display: flex;
}
.h-full {
height: 100%;
}
.flex-1 {
flex: 1 1 0;
}
.flex-2 {
flex: 2 1 0;
}
.flex-col {
flex-direction: column;
}
.flex-auto {
flex: 1 1 auto;
}
@media only screen and (max-width: 600px) {
.container2 {
display: none;
}
}
body, html {
height: 100%;
width: 100%;
}
JavaScript
const chart = {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
legend: {
align: 'right',
verticalAlign: 'middle',
layout: 'vertical',
itemMarginBottom: 10,
margin: 20,
labelFormat: '{name} ({percentage:.1f}%)',
itemStyle: {
fontWeight: 500,
},
},
title: {
text: 'Browser market shares in January, 2018'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
point: {
valueSuffix: '%'
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: false,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Chrome',
y: 61.41,
sliced: true,
selected: true
}, {
name: 'Internet Explorer',
y: 11.84
}, {
name: 'Firefox',
y: 10.85
}, {
name: 'Edge',
y: 4.67
}, {
name: 'Safari',
y: 4.18
}, {
name: 'Sogou Explorer',
y: 1.64
}, {
name: 'Opera',
y: 1.6
}, {
name: 'QQ',
y: 1.2
}, {
name: 'Other',
y: 2.61
}]
}]
}
Highcharts.chart('container', chart);
Highcharts.chart('container2', chart);
Highcharts.chart('container3', {
chart: {
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
...