JSFiddle - React, Tailwind, and code Playground
by Sundarapandiyan_pa
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.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: 800px;
}
.highcharts-tooltip h3 {
margin: 0.3em 0;
}
.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.chart('container', {
chart: {
type: 'bubble',
plotBorderWidth: 1,
zoomType: 'xy',
events: {
load: function(event) {
this.yAxis[0].setExtremes(-this.yAxis[0].max, this.yAxis[0].max);
this.xAxis[0].setExtremes(-this.yAxis[0].max, this.yAxis[0].max);
}
}
},
legend: {
enabled: false
},
title: {
text: 'Sugar and fat intake per country'
},
xAxis: {
gridLineWidth: 1,
title: {
text: 'Daily fat intake'
},
labels: {
format: '{value} gr'
},
plotLines: [{
color: 'grey',
width: 1,
value: 0,
zIndex: 3
}]
},
yAxis: {
startOnTick: false,
endOnTick: false,
title: {
text: 'Daily sugar intake'
},
labels: {
format: '{value} gr'
},
maxPadding: 0.2,
plotLines: [{
color: 'grey',
width: 1,
value: 0,
zIndex: 3
}]
},
tooltip: {
useHTML: true,
headerFormat: '<table>',
pointFormat: '<tr><th colspan="2"><h3>{point.country}</h3></th></tr>' +
'<tr><th>Fat intake:</th><td>{point.x}g</td></tr>' +
'<tr><th>Sugar intake:</th><td>{point.y}g</td></tr>' +
'<tr><th>Obesity (adults):</th><td>{point.z}%</td></tr>',
footerFormat: '</table>',
followPointer: true
},
plotOptions: {
series: {
//colorByPoint: true,
dataLabels: {
enabled: true,
format: '{point.name}'
},
point: {
events: {
click: function() {
this.color = "red";
}
}
}
}
},
series: [{
data: [{
x: 65,
y: -65,
z: 13.8,
name: 'BE',
country: 'Belgium',
color: "red"
},
{
x: 56.5,
y: -82.9,
z: 14.7,
name: 'DE',
country: 'Germany'
},
{
x: 50.8,
y: -61.5,
z: 15.8,
name: 'FI',
country: 'Finland'
},
{
x:...