From 8db39877af12e87b0b3737a8a22b3ba7511aaa12 Mon Sep 17 00:00:00 2001 From: Max van der Schee <26795741+mvdschee@users.noreply.github.com> Date: Fri, 17 Dec 2021 10:56:52 +0700 Subject: [PATCH 1/2] Added dynamic formating based on index of dataset --- docs/assets/js/index.js | 5 ++++- src/js/charts/AxisChart.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/assets/js/index.js b/docs/assets/js/index.js index 48785f0a..239ec31c 100644 --- a/docs/assets/js/index.js +++ b/docs/assets/js/index.js @@ -39,7 +39,10 @@ let typeChartArgs = { tooltipOptions: { formatTooltipX: d => (d + '').toUpperCase(), - formatTooltipY: d => d + ' pts', + formatTooltipY: (d, i) => { + let suffix = (i === 0) ? ' pts' : (i === 1) ? ' $' : ' %'; + return d + suffix; + }, } }; diff --git a/src/js/charts/AxisChart.js b/src/js/charts/AxisChart.js index 9c06bbd2..2f3bf0f1 100644 --- a/src/js/charts/AxisChart.js +++ b/src/js/charts/AxisChart.js @@ -369,7 +369,7 @@ export default class AxisChart extends BaseChart { value: value, yPos: set.yPositions[index], color: this.colors[i], - formatted: formatY ? formatY(value) : value, + formatted: formatY ? formatY(value, i) : value, }; }); From 4a1112f41e10afba31b12b2c89129801ca71b1c7 Mon Sep 17 00:00:00 2001 From: Max van der Schee <26795741+mvdschee@users.noreply.github.com> Date: Fri, 17 Dec 2021 11:00:10 +0700 Subject: [PATCH 2/2] updated docs example, changed let to const --- docs/assets/js/index.js | 2 +- docs/index.html | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/assets/js/index.js b/docs/assets/js/index.js index 239ec31c..a63c86c1 100644 --- a/docs/assets/js/index.js +++ b/docs/assets/js/index.js @@ -40,7 +40,7 @@ let typeChartArgs = { tooltipOptions: { formatTooltipX: d => (d + '').toUpperCase(), formatTooltipY: (d, i) => { - let suffix = (i === 0) ? ' pts' : (i === 1) ? ' $' : ' %'; + const suffix = (i === 0) ? ' pts' : (i === 1) ? ' $' : ' %'; return d + suffix; }, } diff --git a/docs/index.html b/docs/index.html index 1f5ba76c..2f236a92 100644 --- a/docs/index.html +++ b/docs/index.html @@ -71,7 +71,10 @@
Create a chart
tooltipOptions: { formatTooltipX: d => (d + '').toUpperCase(), - formatTooltipY: d => d + ' pts', + formatTooltipY: (d, i) => { + const suffix = (i === 0) ? ' pts' : (i === 1) ? ' $' : ' %'; + return d + suffix; + }, } });