Skip to content

Commit

Permalink
Dashboard : hover label in bar and currency in bar
Browse files Browse the repository at this point in the history
  • Loading branch information
dandiAW committed Feb 21, 2025
1 parent 8e34667 commit df230b9
Showing 1 changed file with 50 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,60 @@ function NumberDashboard(shop: any) {
return route(shop?.name, shop?.parameters)
}
const setChartOptions = () => ({
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false,
},
tooltip: {
callbacks: {
title: (tooltipItems) => {
const index = tooltipItems[0].dataIndex
return props.visual.label[index]
const setChartOptions = () => {
// Base chart options
const options: any = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false,
},
tooltip: {
callbacks: {
title: function (tooltipItems) {
if (
props.visual &&
props.visual.value.hover_labels &&
tooltipItems.length > 0
) {
return props.visual.value.hover_labels[tooltipItems[0].dataIndex]
}
return tooltipItems[0].label
},
label: (context) => {
const value = parseFloat(context.parsed.y ?? context.parsed) || 0
const currencyCode = props.widget.currency_code
if (currencyCode) {
return locale.currencyFormat(currencyCode, value)
}
return locale.number(value)
},
},
},
},
}
label: (context) => {
const index = context.dataIndex
const hoverLabels = props.visual.hoverLabels
if (hoverLabels && hoverLabels[index]) {
return hoverLabels[index]
}
return context.formattedValue
// Only apply y-axis currency formatting for bar charts
if (props.visual && props.visual.type === "bar") {
options.scales = {
y: {
ticks: {
callback: (value) => {
const numericValue = Number(value) || 0
const currencyCode = props.widget.currency_code
if (currencyCode) {
return locale.currencyFormat(currencyCode, numericValue)
}
return locale.number(numericValue)
},
},
},
},
},
})
}
}
return options
}
// const chartLabels = ["1", "2", "3", "4", "5", "6", "7", "8"]
// const chartData = [10, 20, 15, 25, 20, 18, 22, 10]
Expand Down

0 comments on commit df230b9

Please sign in to comment.