Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Adding axis title examples for line, area, vertical bar and vertical stacked bar charts",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import * as React from 'react';
import { AreaChart, ICustomizedCalloutData } from '@fluentui/react-charting';
import { IAreaChartProps, ChartHoverCard } from '@fluentui/react-charting';
import { ChoiceGroup, IChoiceGroupOption } from '@fluentui/react/lib/ChoiceGroup';
import { Toggle } from '@fluentui/react/lib/Toggle';

interface IAreaChartBasicState {
width: number;
height: number;
isCalloutselected: boolean;
showAxisTitles: boolean;
}

const options: IChoiceGroupOption[] = [
Expand All @@ -21,6 +23,7 @@ export class AreaChartBasicExample extends React.Component<{}, IAreaChartBasicSt
width: 700,
height: 300,
isCalloutselected: false,
showAxisTitles: true,
};
}

Expand All @@ -43,6 +46,11 @@ export class AreaChartBasicExample extends React.Component<{}, IAreaChartBasicSt
}
};

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

private _basicExample(): JSX.Element {
const chart1Points = [
{
Expand Down Expand Up @@ -176,28 +184,64 @@ export class AreaChartBasicExample extends React.Component<{}, IAreaChartBasicSt
/>

<ChoiceGroup options={options} defaultSelectedKey="basicExample" onChange={this._onChange} label="Pick one" />
<div style={rootStyle}>
<AreaChart
culture={window.navigator.language}
height={this.state.height}
width={this.state.width}
data={chartData}
showYAxisGridLines={true}
enablePerfOptimization={true}
// eslint-disable-next-line react/jsx-no-bind
onRenderCalloutPerDataPoint={(props: ICustomizedCalloutData) =>
props && this.state.isCalloutselected ? (
<ChartHoverCard
XValue={props.x.toString()}
Legend={'Custom Legend'}
YValue={`${props.values[0].yAxisCalloutData || props.values[0].y} h`}
color={'red'}
/>
) : null
}
enableReflow={true}
/>
</div>
<Toggle
label="Toggle Axis titles"
onText="Show axis titles"
offText="Hide axis titles"
checked={this.state.showAxisTitles}
onChange={this._onToggleAxisTitlesCheckChange}
styles={{ root: { marginTop: '10px' } }}
/>
{this.state.showAxisTitles && (
<div style={rootStyle}>
<AreaChart
culture={window.navigator.language}
height={this.state.height}
width={this.state.width}
data={chartData}
showYAxisGridLines={true}
enablePerfOptimization={true}
// eslint-disable-next-line react/jsx-no-bind
onRenderCalloutPerDataPoint={(props: ICustomizedCalloutData) =>
props && this.state.isCalloutselected ? (
<ChartHoverCard
XValue={props.x.toString()}
Legend={'Custom Legend'}
YValue={`${props.values[0].yAxisCalloutData || props.values[0].y} h`}
color={'red'}
/>
) : null
}
enableReflow={true}
yAxisTitle={this.state.showAxisTitles ? 'Variation of stock market prices' : undefined}
xAxisTitle={this.state.showAxisTitles ? 'Number of days' : undefined}
/>
</div>
)}
{!this.state.showAxisTitles && (
<div style={rootStyle}>
<AreaChart
culture={window.navigator.language}
height={this.state.height}
width={this.state.width}
data={chartData}
showYAxisGridLines={true}
enablePerfOptimization={true}
// eslint-disable-next-line react/jsx-no-bind
onRenderCalloutPerDataPoint={(props: ICustomizedCalloutData) =>
props && this.state.isCalloutselected ? (
<ChartHoverCard
XValue={props.x.toString()}
Legend={'Custom Legend'}
YValue={`${props.values[0].yAxisCalloutData || props.values[0].y} h`}
color={'red'}
/>
) : null
}
enableReflow={true}
/>
</div>
)}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ILineChartBasicState {
width: number;
height: number;
allowMultipleShapes: boolean;
showAxisTitles: boolean;
}

export class LineChartBasicExample extends React.Component<{}, ILineChartBasicState> {
Expand All @@ -16,6 +17,7 @@ export class LineChartBasicExample extends React.Component<{}, ILineChartBasicSt
width: 700,
height: 300,
allowMultipleShapes: false,
showAxisTitles: true,
};
}

Expand All @@ -32,6 +34,10 @@ export class LineChartBasicExample extends React.Component<{}, ILineChartBasicSt
private _onShapeChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ allowMultipleShapes: checked });
};
private _onToggleAxisTitlesCheckChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.forceUpdate();
this.setState({ showAxisTitles: checked });
};

private _basicExample(): JSX.Element {
const data: IChartProps = {
Expand Down Expand Up @@ -143,7 +149,6 @@ export class LineChartBasicExample extends React.Component<{}, ILineChartBasicSt
};

const rootStyle = { width: `${this.state.width}px`, height: `${this.state.height}px` };
const margins = { left: 35, top: 20, bottom: 35, right: 20 };

return (
<>
Expand Down Expand Up @@ -174,21 +179,48 @@ export class LineChartBasicExample extends React.Component<{}, ILineChartBasicSt
onChange={this._onShapeChange}
checked={this.state.allowMultipleShapes}
/>
<div style={rootStyle}>
<LineChart
culture={window.navigator.language}
data={data}
legendsOverflowText={'Overflow Items'}
yMinValue={200}
yMaxValue={301}
height={this.state.height}
width={this.state.width}
margins={margins}
xAxisTickCount={10}
allowMultipleShapesForPoints={this.state.allowMultipleShapes}
enablePerfOptimization={true}
/>
</div>
<Toggle
label="Toggle Axis titles"
onText="Show axis titles"
offText="Hide axis titles"
checked={this.state.showAxisTitles}
onChange={this._onToggleAxisTitlesCheckChange}
styles={{ root: { marginTop: '10px' } }}
/>
{this.state.showAxisTitles && (
<div style={rootStyle}>
<LineChart
culture={window.navigator.language}
data={data}
legendsOverflowText={'Overflow Items'}
yMinValue={200}
yMaxValue={301}
height={this.state.height}
width={this.state.width}
xAxisTickCount={10}
allowMultipleShapesForPoints={this.state.allowMultipleShapes}
enablePerfOptimization={true}
yAxisTitle={this.state.showAxisTitles ? 'Different categories of mail flow' : undefined}
xAxisTitle={this.state.showAxisTitles ? 'Values of each category' : undefined}
/>
</div>
)}
{!this.state.showAxisTitles && (
<div style={rootStyle}>
<LineChart
culture={window.navigator.language}
data={data}
legendsOverflowText={'Overflow Items'}
yMinValue={200}
yMaxValue={301}
height={this.state.height}
width={this.state.width}
xAxisTickCount={10}
allowMultipleShapesForPoints={this.state.allowMultipleShapes}
enablePerfOptimization={true}
/>
</div>
)}
</>
);
}
Expand Down
Loading