Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions highcharts-api/highcharts/06-stacked-bar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

</head>

<body>
<div id="container"></div>
<div id="container"></div>
</body>

<script src="main.js"></script>
<script src="main.js"></script>
92 changes: 92 additions & 0 deletions highcharts-api/highcharts/06-stacked-bar/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const categories = ['Data', 'Emails', 'Duplicates', 'Support'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for the future - this more naturally should just go to the xAxis.categories setup


Highcharts.chart('container', {
chart: {
type: 'bar',
marginTop: 20,
events: {
load: function() {
const chart = this;

chart.customLabels = [];
chart.customButtons = [];
},
render: function() {
const chart = this;
const { renderer, series, xAxis, customLabels, customButtons } = chart;

// Add buttons
series[0].points.forEach((point, i) => {
if (!customButtons[i]) {
customButtons[i] = renderer
.button('How to fix', 0, 0, function () {}, {
height: 6,
zIndex: 10,
stroke: 'blue',
})
.css({ 'font-size': '13px' })
.add();
}

const pointWidth = point.shapeArgs.width;
const pointX = chart.plotTop + point.shapeArgs.x;

customButtons[i].attr({
x: chart.plotWidth,
y: pointX + pointWidth / 2 - customButtons[i].height / 2
});
});

// Add labels
if (customLabels.length == 0) {
customLabels.push(
...['Issue', 'Record Count', 'Action']
.map(title =>
renderer.label(title, 0, chart.plotTop - 25)
.css({ 'font-size': '10px' })
.add()
)
);
}

customLabels[0].attr({ x: 3 });
customLabels[1].attr({ x: chart.plotLeft - 3 });
customLabels[2].attr({ x: chart.plotWidth });
}
}
},
title: {
text: null
},
legend: {
enabled: false
},
xAxis: {
lineWidth: 0,
gridLineWidth: 1,
categories
},
yAxis: {
title: { text: 'Amount' },
softMax: 400,
gridLineWidth: 0,
stackLabels: {
enabled: true,
format: '{total} K'
}
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
data: [100, 130, 35, 30],
}, {
data: [15, 0, 15, 10],
}, {
data: [110, 110, 30, 40]
}, {
data: [15, 0, 10, 5]
}]
});