Skip to content

Instantly share code, notes, and snippets.

@FourSeventy
Created August 22, 2024 17:25
Show Gist options
  • Save FourSeventy/b936c2fc03f0b5a7f5785132b7f52533 to your computer and use it in GitHub Desktop.
Save FourSeventy/b936c2fc03f0b5a7f5785132b7f52533 to your computer and use it in GitHub Desktop.
Highcharts issue
var myChart = Highcharts.chart("performance-by-channel-chart", {
colors: colors,
chart: {
type: "bar",
style: {
fontFamily: '"Inter var",sans-serif',
fontWeight: "normal",
fontSize: '13px',
},
marginRight: 70,
},
credits: false,
title: {
text: undefined,
},
xAxis: {
type: "category",
title: {
text: null,
},
},
yAxis: [
{
title: {
text: undefined,
},
labels: {
formatter: function () {
if (format == "revenueCurrency") {
return new Intl.NumberFormat("EN", {
style: "currency",
currency: currency,
}).format(this.value);
} else if (format == "percent") {
return formatPercent(this.value);
} else if (format == "numberDecimal") {
return formatDecimal(this.value);
} else if (format == "numberSingleDecimal") {
return formatSingleDecimal(this.value);
} else if (format == "number") {
return formatNumber(this.value);
} else {
return this.axis.defaultLabelFormatter.call(this);
}
},
},
},
],
legend: {
enabled: false,
},
tooltip: {
borderColor: "#484D59",
formatter: function () {
return this.points.reduce(function (s, point) {
if (format == "revenueCurrency") {
var val = new Intl.NumberFormat("EN", {
style: "currency",
currency: currency,
}).format(point.y);
} else if (format == "percent") {
var val = formatPercent(point.y);
} else if (format == "numberDecimal") {
var val = formatDecimal(point.y);
} else if (format == "numberSingleDecimal") {
var val = formatSingleDecimal(point.y);
} else if (format == "number") {
var val = formatNumber(point.y);
} else {
var val = numeral(point.y).format("0,0");
}
return s + '<br/><span style="color:' + point.color + '">\u25CF</span> ' + point.series.name + ": " + "<b>" + val + "</b>";
}, "<b>" + this.points[0].key + "</b>");
},
shared: true,
},
plotOptions: {
series: {
connectNulls: true,
lineWidth: 1,
states: {
hover: {
lineWidth: 1,
},
inactive: {
opacity: 1,
},
},
},
bar: {
dataLabels: {
enabled: true,
formatter: function () {
if (format == "revenueCurrency") {
var val = new Intl.NumberFormat("EN", {
style: "currency",
currency: currency,
}).format(this.y);
} else if (format == "percent") {
var val = formatPercent(this.y);
} else if (format == "numberDecimal") {
var val = formatDecimal(this.y);
} else if (format == "numberSingleDecimal") {
var val = formatSingleDecimal(this.y);
} else if (format == "number") {
var val = formatNumber(this.y);
} else {
var val = numeral(this.y).format("0,0");
}
return (
val +
` <span class="italic" style="color: #bdbdbd; font-size: 0.575rem;">(${formatCellPercent(
(this.y / metricTotals[name]) * 100
)})</span>`
);
},
},
},
},
credits: {
enabled: false,
},
series: [
{
type: "bar",
name: label,
colorByPoint: false,
data: channelsMetric,
xAxis: 0,
dataSorting: {
enabled: true,
sortKey: "y",
},
},
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment