diff --git a/change/@fluentui-react-charting-f8073f84-d26a-4b28-992e-379202a63f5d.json b/change/@fluentui-react-charting-f8073f84-d26a-4b28-992e-379202a63f5d.json
new file mode 100644
index 0000000000000..4ee5b0e301fd3
--- /dev/null
+++ b/change/@fluentui-react-charting-f8073f84-d26a-4b28-992e-379202a63f5d.json
@@ -0,0 +1,7 @@
+{
+ "type": "patch",
+ "comment": "Enable Controlled Legends working in declarative HBC",
+ "packageName": "@fluentui/react-charting",
+ "email": "74965306+Anush2303@users.noreply.github.com",
+ "dependentChangeType": "patch"
+}
diff --git a/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.tsx b/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.tsx
index 10246111177c2..8cb522e55edd4 100644
--- a/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.tsx
+++ b/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.tsx
@@ -84,7 +84,7 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
color: '',
dataForHoverCard: 0,
isCalloutVisible: false,
- isLegendSelected: false,
+ isLegendSelected: props.legendProps?.selectedLegend !== undefined,
isLegendHovered: false,
refSelected: null,
selectedLegendTitle: props.legendProps?.selectedLegend ?? '',
@@ -583,6 +583,15 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
const { xBarScale, yBarScale } = this._getScales(containerHeight, containerWidth, false);
const { useSingleColor = false } = this.props;
const bars = this._points.map((point: IHorizontalBarChartWithAxisDataPoint, index: number) => {
+ let shouldHighlight = true;
+ if (this.state.isLegendHovered || this.state.isLegendSelected) {
+ shouldHighlight = this.state.selectedLegendTitle === point.legend;
+ }
+ this._classNames = getClassNames(this.props.styles!, {
+ theme: this.props.theme!,
+ legendColor: this.state.color,
+ shouldHighlight,
+ });
const barHeight: number = Math.max(yBarScale(point.y), 0);
if (barHeight < 1) {
return ;
@@ -627,6 +636,7 @@ export class HorizontalBarChartWithAxisBase extends React.Component<
diff --git a/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/__snapshots__/HorizontalBarChartWithAxis.test.tsx.snap b/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/__snapshots__/HorizontalBarChartWithAxis.test.tsx.snap
index eeabb9f133817..ae589f61329a7 100644
--- a/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/__snapshots__/HorizontalBarChartWithAxis.test.tsx.snap
+++ b/packages/charts/react-charting/src/components/HorizontalBarChartWithAxis/__snapshots__/HorizontalBarChartWithAxis.test.tsx.snap
@@ -2128,6 +2128,11 @@ exports[`HorizontalBarChartWithAxis snapShot testing renders showToolTipForYAxis