import * as React from 'react';
import { IVSChartDataPoint, IVerticalStackedChartProps, VerticalStackedBarChart } from '@fluentui/react-charting';
import { DefaultPalette } from '@fluentui/react/lib/Styling';
import { Checkbox } from '@fluentui/react/lib/Checkbox';
interface IVerticalStackedBarState {
width: number;
height: number;
barGapMax: number;
showLine: boolean;
}
export class VerticalStackedBarChartBasicExample extends React.Component<{}, IVerticalStackedBarState> {
constructor(props: IVerticalStackedChartProps) {
super(props);
this.state = {
width: 650,
height: 350,
showLine: true,
barGapMax: 2,
};
}
public render(): JSX.Element {
return
{this._basicExample()}
;
}
private _onWidthChange = (e: React.ChangeEvent) => {
this.setState({ width: parseInt(e.target.value, 10) });
};
private _onHeightChange = (e: React.ChangeEvent) => {
this.setState({ height: parseInt(e.target.value, 10) });
};
private _onShowLineChange = (ev: React.FormEvent, checked: boolean): void => {
this.setState({ showLine: checked });
};
private _basicExample(): JSX.Element {
const { showLine } = this.state;
const firstChartPoints: IVSChartDataPoint[] = [
{
legend: 'Metadata1',
data: 40,
color: DefaultPalette.accent,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '40%',
},
{
legend: 'Metadata2',
data: 5,
color: DefaultPalette.blueMid,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '5%',
},
{
legend: 'Metadata3',
data: 20,
color: DefaultPalette.blueLight,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '20%',
},
];
const secondChartPoints: IVSChartDataPoint[] = [
{
legend: 'Metadata1',
data: 30,
color: DefaultPalette.accent,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '30%',
},
{
legend: 'Metadata2',
data: 20,
color: DefaultPalette.blueMid,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '20%',
},
{
legend: 'Metadata3',
data: 40,
color: DefaultPalette.blueLight,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '40%',
},
];
const thirdChartPoints: IVSChartDataPoint[] = [
{
legend: 'Metadata1',
data: 44,
color: DefaultPalette.accent,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '44%',
},
{
legend: 'Metadata2',
data: 28,
color: DefaultPalette.blueMid,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '28%',
},
{
legend: 'Metadata3',
data: 30,
color: DefaultPalette.blueLight,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '30%',
},
];
const fourthChartPoints: IVSChartDataPoint[] = [
{
legend: 'Metadata1',
data: 88,
color: DefaultPalette.accent,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '88%',
},
{
legend: 'Metadata2',
data: 22,
color: DefaultPalette.blueMid,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '22%',
},
{
legend: 'Metadata3',
data: 30,
color: DefaultPalette.blueLight,
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '30%',
},
];
const data: IVerticalStackedChartProps[] = [
{
chartData: firstChartPoints,
xAxisPoint: 0,
...(showLine && {
lineData: [
{ y: 42, legend: 'Supported Builds', color: DefaultPalette.magenta },
{ y: 10, legend: 'Recommended Builds', color: DefaultPalette.redDark },
],
}),
},
{
chartData: secondChartPoints,
xAxisPoint: 20,
...(showLine && {
lineData: [{ y: 33, legend: 'Supported Builds', color: DefaultPalette.magenta }],
}),
},
{
chartData: thirdChartPoints,
xAxisPoint: 40,
...(showLine && {
lineData: [
{ y: 60, legend: 'Supported Builds', color: DefaultPalette.magenta },
{ y: 20, legend: 'Recommended Builds', color: DefaultPalette.redDark },
],
}),
},
{
chartData: firstChartPoints,
xAxisPoint: 60,
...(showLine && {
lineData: [
{ y: 41, legend: 'Supported Builds', color: DefaultPalette.magenta },
{ y: 10, legend: 'Recommended Builds', color: DefaultPalette.redDark },
],
}),
},
{
chartData: fourthChartPoints,
xAxisPoint: 80,
...(showLine && {
lineData: [
{ y: 100, legend: 'Supported Builds', color: DefaultPalette.magenta },
{ y: 70, legend: 'Recommended Builds', color: DefaultPalette.redDark },
],
}),
},
{
chartData: firstChartPoints,
xAxisPoint: 100,
},
];
const rootStyle = { width: `${this.state.width}px`, height: `${this.state.height}px` };
return (
<>
this.setState({ barGapMax: +e.target.value })}
/>
>
);
}
}