Styled mode pie
author(s):
Torstein Hønsi
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>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Charts can be styled using CSS, such as this example overriding
the default styles for a pie chart. This can be done without the
use of Javascript, allowing designers and developers to better
collaborate on chart design.
</p>
</figure>
CSS
@import url("https://code.highcharts.com/css/highcharts.css");
.highcharts-pie-series .highcharts-point {
stroke: #ede;
stroke-width: 2px;
}
.highcharts-pie-series .highcharts-data-label-connector {
stroke: silver;
stroke-dasharray: 2, 2;
stroke-width: 2px;
}
.highcharts-figure,
.highcharts-data-table table {
min-width: 320px;
max-width: 600px;
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
// Data retrieved from https://gs.statcounter.com/vendor-market-share/mobile/
Highcharts.chart('container', {
chart: {
styledMode: true
},
title: {
text: 'Mobile vendor market share, 2021'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
innerSize: '30%',
depth: 45,
dataLabels: {
enabled: false
},
showInLegend: true,
inactiveOtherPoints: true
},
series: {
colorByPoint: true
}
},
series: [{
type: 'pie',
allowPointSelect: true,
keys: ['name', 'y', 'selected', 'sliced'],
data: [
['Samsung', 27.79, true, true],
['Apple', 27.34, false],
['Xiaomi', 10.87, false],
['Huawei', 8.48, false],
['Oppo', 5.38, false],
['Vivo', 4.17, false],
['Realme', 2.57, false],
['Unknown', 2.45, false],
['Motorola', 2.22, false],
['LG', 1.53, false],
['Other', 7.2, false]
],
showInLegend: true
}]
});