Skip to content

Commit

Permalink
Adding example for legend multi select for VSBC
Browse files Browse the repository at this point in the history
  • Loading branch information
srmukher committed Dec 13, 2024
1 parent 216f82e commit 5ede767
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/charts/react-charting/etc/react-charting.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ export interface IVerticalStackedBarChartProps extends ICartesianChartProps {
barMinimumHeight?: number;
barWidth?: number | 'default' | 'auto';
calloutProps?: Partial<ICalloutProps>;
canSelectMultipleLegends?: boolean;
chartTitle?: string;
// @deprecated
colors?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,16 +651,12 @@ export class VerticalStackedBarChartBase extends React.Component<
overflowText={this.props.legendsOverflowText}
{...this.props.legendProps}
onChange={this._onLegendChange}
canSelectMultipleLegends
canSelectMultipleLegends={this.props.canSelectMultipleLegends}
/>
);
}

private _onLegendChange = (
selectedLegends: string[],
event: React.MouseEvent<HTMLButtonElement>,
legend: ILegend,
) => {
private _onLegendChange = (selectedLegends: string[]) => {
this.setState({ selectedLegends });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export interface IVerticalStackedBarChartProps extends ICartesianChartProps {
* The prop used to enable rounded corners for the chart.
*/
roundCorners?: boolean;

/**
* The prop used to enable multiple legend selection.
* @default false
*/
canSelectMultipleLegends?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IVerticalStackedBarState {
margins: {};
enableGradient: boolean;
roundCorners: boolean;
legendMultiSelect: boolean;
}

export class VerticalStackedBarChartBasicExample extends React.Component<{}, IVerticalStackedBarState> {
Expand All @@ -41,6 +42,7 @@ export class VerticalStackedBarChartBasicExample extends React.Component<{}, IVe
},
enableGradient: false,
roundCorners: false,
legendMultiSelect: false,
};
}

Expand Down Expand Up @@ -94,6 +96,10 @@ export class VerticalStackedBarChartBasicExample extends React.Component<{}, IVe
this.setState({ roundCorners: checked });
};

private _onToggleLegendMultiSelect = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ legendMultiSelect: checked });
};

private _basicExample(): JSX.Element {
const { showLine } = this.state;
const firstChartPoints: IVSChartDataPoint[] = [
Expand Down Expand Up @@ -307,6 +313,13 @@ export class VerticalStackedBarChartBasicExample extends React.Component<{}, IVe
<Toggle label="Enable Gradient" onText="ON" offText="OFF" onChange={this._onEnableGradientChange} />
&nbsp;&nbsp;
<Toggle label="Rounded Corners" onText="ON" offText="OFF" onChange={this._onRoundCornersChange} />
&nbsp;&nbsp;
<Toggle
label="Select Multiple Legends"
onText="ON"
offText="OFF"
onChange={this._onToggleLegendMultiSelect}
/>
</div>
{this.state.showAxisTitles && (
<div style={rootStyle}>
Expand All @@ -328,6 +341,7 @@ export class VerticalStackedBarChartBasicExample extends React.Component<{}, IVe
xAxisTitle={this.state.showAxisTitles ? 'Number of days' : undefined}
enableGradient={this.state.enableGradient}
roundCorners={this.state.roundCorners}
canSelectMultipleLegends={this.state.legendMultiSelect}
/>
</div>
)}
Expand Down

0 comments on commit 5ede767

Please sign in to comment.