Skip to content

Commit

Permalink
add update js, css code to display data-title attribute for percentag…
Browse files Browse the repository at this point in the history
…e bar chart component, for #413
  • Loading branch information
poojagunturu96 committed Oct 14, 2024
1 parent 35eca3c commit 10d0893
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/js/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ class MiddChart {
borderColor: '#ccc',
callbacks: {
label: (context) => {
// console.log(context);
return `${context.dataset.label}: ${context.raw}${valueSuffix}`;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/js/components/percent-bar-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ interface PercentBarProps {
labels: string[];
datasets: DataSet[];
colors: string[];
title?: string;
}

const PercentBarChart: FunctionComponent<PercentBarProps> = ({
labels,
datasets,
colors
colors,
title
}) => {
// reconstruct a data array with the first dataset since the component only supports
// rendering one dataset.
Expand Down Expand Up @@ -73,7 +75,8 @@ const PercentBarChart: FunctionComponent<PercentBarProps> = ({
const sortedLabels = preparedData.map((data: any) => data.label);

return (
<div>
<figure className='chart--percentage-bar'>
{title && <figcaption>{title}</figcaption>}
<div
style={{
display: 'flex',
Expand Down Expand Up @@ -101,7 +104,7 @@ const PercentBarChart: FunctionComponent<PercentBarProps> = ({
})}
</div>
<Legend items={sortedLabels} colors={colors} />
</div>
</figure>
);
};

Expand Down
8 changes: 8 additions & 0 deletions src/scss/components/_chart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
margin-right: 0;
}

.chart--percentage-bar {
figcaption {
font-size: $typescale-2;
font-weight: $font-weight-medium;
text-align: center;
padding: $spacing-4;
}
}
///
//// Chart legend
///
Expand Down

0 comments on commit 10d0893

Please sign in to comment.