import * as React from 'react'; import { IChartProps, ILineChartProps, LineChart, ILineChartDataPoint, DataVizPalette, getColorFromToken, } from '@fluentui/react-charting'; import { Toggle } from '@fluentui/react/lib/Toggle'; import type { JSXElement } from '@fluentui/utilities'; interface ILineChartBasicState { width: number; height: number; allowMultipleShapes: boolean; } export class LineChartLargeDataExample extends React.Component<{}, ILineChartBasicState> { constructor(props: ILineChartProps) { super(props); this.state = { width: 700, height: 300, allowMultipleShapes: false, }; } public render(): JSXElement { 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 _onShapeChange = (ev: React.MouseEvent, checked: boolean) => { this.setState({ allowMultipleShapes: checked }); }; private _getdata = () => { const data: ILineChartDataPoint[] = []; const startdate = new Date('2020-03-01T00:00:00.000Z'); for (let i = 0; i < 10000; i++) { const newDate = new Date(startdate); newDate.setUTCHours(startdate.getUTCHours() + i); data.push({ x: newDate, y: 500000 }); } return data; }; private _getdata2 = () => { const data: ILineChartDataPoint[] = []; const startdate = new Date('2020-03-01T00:00:00.000Z'); for (let i = 1000; i < 9000; i++) { const newDate = new Date(startdate); newDate.setUTCHours(startdate.getUTCHours() + i); data.push({ x: newDate, y: this._getY(i) }); } return data; }; private _getY = (i: number) => { let res: number = 0; const newN = i % 1000; if (newN < 500) { res = newN * newN; } else { res = 1000000 - newN * newN; } return res; }; private _basicExample(): JSXElement { const data: IChartProps = { chartTitle: 'Line Chart', lineChartData: [ { legend: 'From_Legacy_to_O365', data: this._getdata(), color: getColorFromToken(DataVizPalette.color1), onLineClick: () => console.log('From_Legacy_to_O365'), hideNonActiveDots: true, lineOptions: { lineBorderWidth: '4', }, }, { legend: 'All', data: this._getdata2(), color: getColorFromToken(DataVizPalette.color5), lineOptions: { lineBorderWidth: '4', }, }, { legend: 'single point', data: [ { x: new Date('2020-03-05T00:00:00.000Z'), y: 282000, }, ], color: getColorFromToken(DataVizPalette.color9), }, ], }; const rootStyle = { width: `${this.state.width}px`, height: `${this.state.height}px` }; const margins = { left: 35, top: 20, bottom: 35, right: 20 }; return (
); } }