Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise/highcharts 3 #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
109 changes: 109 additions & 0 deletions highcharts-api/highcharts/3-stacked-bar/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Highcharts.chart("container", {
chart: {
type: "bar",
marginTop: 50,
events: {
load() {
this.renderer.text("Issue", 0, 35).add();
this.renderer.text("Record Count", this.plotLeft, 35).add();
this.renderer.text("Action", this.plotWidth, 35).add();

const buttonStyles = {
fill: "#fff",
stroke: "blue",
"stroke-width": 2,
};

const buttons = Array.from({ length: 4 }, (_, index) =>
this.renderer
.button(
"How to fix",
this.plotWidth,
this.axes[0].getThreshold(index) + this.marginBottom,
() => null,
buttonStyles,
buttonStyles
)
.attr(buttonStyles)
.add()
);

this.customButtons = buttons;
},
render() {
const customButtons = this.customButtons;

if (Array.isArray(customButtons) && customButtons.length > 0) {
customButtons.map((button, index) =>
button
.attr(0)
.translate(
this.plotWidth,
this.axes[0].getThreshold(index) +
this.marginBottom -
button.height / 2
)
);
}
},
},
},
title: {
text: undefined,
},
xAxis: {
categories: ["Data", "Emails", "Duplicates", "Support"],
gridLineWidth: 1,
lineWidth: 0,
},
yAxis: {
min: 0,
tickInterval: 50,
gridLineWidth: 0,
title: {
text: "Amount",
},
stackLabels: {
enabled: true,
style: {
fontWeight: "bold",
},
formatter() {
return `${this.total} K`;
},
},
},
legend: {
enabled: false,
},
plotOptions: {
series: {
stacking: "normal",
},
},
credits: {
enabled: false,
},
series: [
{
name: "Element v1",
data: [35, 0, 20, 10],
index: 0,
},
{
name: "Element v2",
data: [95, 90, 40, 45],
index: 1,
},
{
name: "Element v3",
data: [30, 0, 30, 20],
index: 2,
},
{
name: "Element v4",
data: [90, 110, 60, 50],
index: 3,
},
],
});