Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
60 changes: 60 additions & 0 deletions docs/data/charts/composition/LegendTooltipComposition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as React from 'react';
import { ChartDataProvider } from '@mui/x-charts/ChartDataProvider';
import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
import {
LinePlot,
MarkPlot,
lineElementClasses,
markElementClasses,
} from '@mui/x-charts/LineChart';
import { ChartsLegend } from '@mui/x-charts/ChartsLegend';
import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight';

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 LegendTooltipComposition() {
return (
<ChartDataProvider
width={500}
height={300}
series={[{ type: 'line', data: pData, label: 'Sales Data' }]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
margin={{ top: 40, right: 20, bottom: 20, left: 20 }}
>
<ChartsLegend />
<ChartsTooltip />
<ChartsSurface
sx={{
[`& .${lineElementClasses.root}`]: {
stroke: '#8884d8',
strokeWidth: 2,
},
[`& .${markElementClasses.root}`]: {
stroke: '#8884d8',
r: 4,
fill: '#fff',
strokeWidth: 2,
},
}}
>
<ChartsXAxis />
<ChartsYAxis />
<LinePlot />
<MarkPlot />
<ChartsAxisHighlight x="line" />
</ChartsSurface>
</ChartDataProvider>
);
}
60 changes: 60 additions & 0 deletions docs/data/charts/composition/LegendTooltipComposition.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as React from 'react';
import { ChartDataProvider } from '@mui/x-charts/ChartDataProvider';
import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
import {
LinePlot,
MarkPlot,
lineElementClasses,
markElementClasses,
} from '@mui/x-charts/LineChart';
import { ChartsLegend } from '@mui/x-charts/ChartsLegend';
import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight';

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 LegendTooltipComposition() {
return (
<ChartDataProvider
width={500}
height={300}
series={[{ type: 'line', data: pData, label: 'Sales Data' }]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
margin={{ top: 40, right: 20, bottom: 20, left: 20 }}
>
<ChartsLegend />
<ChartsTooltip />
<ChartsSurface
sx={{
[`& .${lineElementClasses.root}`]: {
stroke: '#8884d8',
strokeWidth: 2,
},
[`& .${markElementClasses.root}`]: {
stroke: '#8884d8',
r: 4,
fill: '#fff',
strokeWidth: 2,
},
}}
>
<ChartsXAxis />
<ChartsYAxis />
<LinePlot />
<MarkPlot />
<ChartsAxisHighlight x="line" />
</ChartsSurface>
</ChartDataProvider>
);
}
4 changes: 3 additions & 1 deletion docs/data/charts/composition/composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ It must be rendered inside the Data Provider to get access to the data, but outs
<ChartsSurface>{/* SVG components */}</ChartsSurface>
</ChartDataProvider>

// ❌ Wrong
// ❌ Incorrect
<ChartContainer>
<ChartsLegend />
</ChartContainer>
Expand All @@ -248,6 +248,8 @@ See [HTML components](/x/react-charts/components/#html-components) documentation

You can also add interactive elements such as `<ChartsAxisHighlight />` and `<ChartsTooltip />`.

{{"demo": "LegendTooltipComposition.js" }}

:::info
By default, the container listens to mouse events to keep track of where the mouse is located on the chart.

Expand Down
Loading