Skip to content

Commit

Permalink
Add % on campaign analytics pie chart hover (#2124)
Browse files Browse the repository at this point in the history
Co-authored-by: Kailash Nadh <[email protected]>
  • Loading branch information
Bowrna and knadh authored Nov 5, 2024
1 parent c35ed68 commit 0392582
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 9 additions & 0 deletions frontend/src/components/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const DEFAULT_DONUT = {
},
bodySpacing: 10,
padding: 10,
callbacks: {
label: (item) => {
const data = item.chart.data.datasets[item.datasetIndex];
const total = data.data.reduce((acc, val) => acc + val, 0);
const val = data.data[item.dataIndex];
const percentage = ((val / total) * 100).toFixed(2);
return `${val} (${percentage}%)`;
},
},
},
},
},
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/views/CampaignAnalytics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ export default Vue.extend({
out[c.id] = c;
return out;
}, {});
const campIDs = Object.keys(camps);
// datasets[] array for line chart.
const lines = campIDs.map((id, n) => {
const cId = parseInt(id, 10);
Expand Down Expand Up @@ -242,7 +240,6 @@ export default Vue.extend({
data: points, backgroundColor: chartColors, borderWidth: 6,
}],
};
return { points: { datasets: lines }, donut };
},
Expand All @@ -269,7 +266,6 @@ export default Vue.extend({
getData(typ, camps) {
this.charts[typ].loading = true;
// Call the HTTP API.
this.charts[typ].fn({
id: camps.map((c) => c.id),
Expand Down

0 comments on commit 0392582

Please sign in to comment.