forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Add <ChartsReferenceLine /> component (mui#10597)
Co-authored-by: alexandre <[email protected]> Co-authored-by: Alexandre Fauquette <[email protected]> Co-authored-by: Lukas <[email protected]>
- Loading branch information
1 parent
289ed7a
commit 37ca879
Showing
47 changed files
with
931 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer'; | ||
import { LinePlot } from '@mui/x-charts/LineChart'; | ||
|
||
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis'; | ||
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis'; | ||
import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine'; | ||
|
||
const timeData = [ | ||
new Date(2023, 7, 31), | ||
new Date(2023, 7, 31, 12), | ||
new Date(2023, 8, 1), | ||
new Date(2023, 8, 1, 12), | ||
new Date(2023, 8, 2), | ||
new Date(2023, 8, 2, 12), | ||
new Date(2023, 8, 3), | ||
new Date(2023, 8, 3, 12), | ||
new Date(2023, 8, 4), | ||
]; | ||
|
||
const y1 = [5, 5, 10, 90, 85, 70, 30, 25, 25]; | ||
const y2 = [90, 85, 70, 25, 23, 40, 45, 40, 50]; | ||
|
||
const config = { | ||
series: [ | ||
{ type: 'line', data: y1 }, | ||
{ type: 'line', data: y2 }, | ||
], | ||
height: 400, | ||
xAxis: [ | ||
{ | ||
data: timeData, | ||
scaleType: 'time', | ||
valueFormatter: (date) => | ||
date.getHours() === 0 | ||
? date.toLocaleDateString('fr-FR', { | ||
month: '2-digit', | ||
day: '2-digit', | ||
}) | ||
: date.toLocaleTimeString('fr-FR', { | ||
hour: '2-digit', | ||
}), | ||
}, | ||
], | ||
}; | ||
|
||
export default function ReferenceLine() { | ||
return ( | ||
<Box sx={{ width: '100%', maxWidth: 600 }}> | ||
<ResponsiveChartContainer {...config}> | ||
<LinePlot /> | ||
<ChartsReferenceLine | ||
x={new Date(2023, 8, 2, 9)} | ||
lineStyle={{ strokeDasharray: '10 5' }} | ||
labelStyle={{ fontSize: '10' }} | ||
label={`Wake up\n9AM`} | ||
labelAlign="start" | ||
/> | ||
<ChartsReferenceLine y={50} label="Middle value" labelAlign="end" /> | ||
<ChartsXAxis /> | ||
<ChartsYAxis /> | ||
</ResponsiveChartContainer> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer'; | ||
import { LinePlot } from '@mui/x-charts/LineChart'; | ||
import { LineSeriesType } from '@mui/x-charts/models'; | ||
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis'; | ||
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis'; | ||
import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine'; | ||
|
||
const timeData = [ | ||
new Date(2023, 7, 31), | ||
new Date(2023, 7, 31, 12), | ||
new Date(2023, 8, 1), | ||
new Date(2023, 8, 1, 12), | ||
new Date(2023, 8, 2), | ||
new Date(2023, 8, 2, 12), | ||
new Date(2023, 8, 3), | ||
new Date(2023, 8, 3, 12), | ||
new Date(2023, 8, 4), | ||
]; | ||
|
||
const y1 = [5, 5, 10, 90, 85, 70, 30, 25, 25]; | ||
const y2 = [90, 85, 70, 25, 23, 40, 45, 40, 50]; | ||
|
||
const config = { | ||
series: [ | ||
{ type: 'line', data: y1 }, | ||
{ type: 'line', data: y2 }, | ||
] as LineSeriesType[], | ||
height: 400, | ||
xAxis: [ | ||
{ | ||
data: timeData, | ||
scaleType: 'time', | ||
valueFormatter: (date: Date) => | ||
date.getHours() === 0 | ||
? date.toLocaleDateString('fr-FR', { | ||
month: '2-digit', | ||
day: '2-digit', | ||
}) | ||
: date.toLocaleTimeString('fr-FR', { | ||
hour: '2-digit', | ||
}), | ||
} as const, | ||
], | ||
}; | ||
|
||
export default function ReferenceLine() { | ||
return ( | ||
<Box sx={{ width: '100%', maxWidth: 600 }}> | ||
<ResponsiveChartContainer {...config}> | ||
<LinePlot /> | ||
<ChartsReferenceLine | ||
x={new Date(2023, 8, 2, 9)} | ||
lineStyle={{ strokeDasharray: '10 5' }} | ||
labelStyle={{ fontSize: '10' }} | ||
label={`Wake up\n9AM`} | ||
labelAlign="start" | ||
/> | ||
<ChartsReferenceLine y={50} label="Middle value" labelAlign="end" /> | ||
<ChartsXAxis /> | ||
<ChartsYAxis /> | ||
</ResponsiveChartContainer> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<ResponsiveChartContainer {...config}> | ||
<LinePlot /> | ||
<ChartsReferenceLine | ||
x={new Date(2023, 8, 2, 9)} | ||
lineStyle={{ strokeDasharray: '10 5' }} | ||
labelStyle={{ fontSize: '10' }} | ||
label={`Wake up\n9AM`} | ||
labelAlign="start" | ||
/> | ||
<ChartsReferenceLine y={50} label="Middle value" labelAlign="end" /> | ||
<ChartsXAxis /> | ||
<ChartsYAxis /> | ||
</ResponsiveChartContainer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
import { ChartContainer } from '@mui/x-charts/ChartContainer'; | ||
import { ChartsReferenceLine } from '@mui/x-charts'; | ||
import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart'; | ||
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis'; | ||
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis'; | ||
|
||
const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490]; | ||
const pData = [2400, 1398, 9800, 3908, 4800, 3800, 4300]; | ||
const xLabels = [ | ||
'Page A', | ||
'Page B', | ||
'Page C', | ||
'Page D', | ||
'Page E', | ||
'Page F', | ||
'Page G', | ||
]; | ||
|
||
export default function LineChartWithReferenceLines() { | ||
return ( | ||
<ChartContainer | ||
width={500} | ||
height={300} | ||
series={[ | ||
{ data: pData, label: 'pv', type: 'line' }, | ||
{ data: uData, label: 'uv', type: 'line' }, | ||
]} | ||
xAxis={[{ scaleType: 'point', data: xLabels }]} | ||
> | ||
<LinePlot /> | ||
<MarkPlot /> | ||
<ChartsReferenceLine | ||
x="Page C" | ||
label="Max PV PAGE" | ||
lineStyle={{ stroke: 'red' }} | ||
/> | ||
<ChartsReferenceLine y={9800} label="Max" lineStyle={{ stroke: 'red' }} /> | ||
<ChartsXAxis /> | ||
<ChartsYAxis /> | ||
</ChartContainer> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
docs/data/charts/line-demo/LineChartWithReferenceLines.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
import { ChartContainer } from '@mui/x-charts/ChartContainer'; | ||
import { ChartsReferenceLine } from '@mui/x-charts'; | ||
import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart'; | ||
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis'; | ||
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis'; | ||
|
||
const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490]; | ||
const pData = [2400, 1398, 9800, 3908, 4800, 3800, 4300]; | ||
const xLabels = [ | ||
'Page A', | ||
'Page B', | ||
'Page C', | ||
'Page D', | ||
'Page E', | ||
'Page F', | ||
'Page G', | ||
]; | ||
|
||
export default function LineChartWithReferenceLines() { | ||
return ( | ||
<ChartContainer | ||
width={500} | ||
height={300} | ||
series={[ | ||
{ data: pData, label: 'pv', type: 'line' }, | ||
{ data: uData, label: 'uv', type: 'line' }, | ||
]} | ||
xAxis={[{ scaleType: 'point', data: xLabels }]} | ||
> | ||
<LinePlot /> | ||
<MarkPlot /> | ||
<ChartsReferenceLine | ||
x="Page C" | ||
label="Max PV PAGE" | ||
lineStyle={{ stroke: 'red' }} | ||
/> | ||
<ChartsReferenceLine y={9800} label="Max" lineStyle={{ stroke: 'red' }} /> | ||
<ChartsXAxis /> | ||
<ChartsYAxis /> | ||
</ChartContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.