Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[charts] New HTML legend & styles #15733

Merged
merged 194 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 167 commits
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
2e80d0c
initial remove props
JCQuintas Nov 28, 2024
0410939
Merge commit '82d46ab329a11bf9308e8a1cf57786ac0cec37ad' into html-def…
JCQuintas Dec 2, 2024
753216d
Merge commit 'f9df87afcc86e2278daf9c1d47476817bddfc9af' into html-def…
JCQuintas Dec 4, 2024
c5dc548
initial mark
JCQuintas Dec 4, 2024
de72d1c
initial working html charts legend
JCQuintas Dec 4, 2024
4782dbf
type to markType
JCQuintas Dec 4, 2024
f944ddb
Add prepend keys to internals
JCQuintas Dec 4, 2024
28b5d47
handle most significant props
JCQuintas Dec 4, 2024
7b6fb45
Merge branch 'master' into html-default-legend
JCQuintas Dec 4, 2024
276bb0e
Fix label styling
JCQuintas Dec 5, 2024
12383d7
remove hardcoded styles
JCQuintas Dec 5, 2024
60ee4fa
Allow label items to have classes prop
JCQuintas Dec 5, 2024
88f4393
Add classes to ChartsLegend
JCQuintas Dec 5, 2024
55e8c3b
divide types
JCQuintas Dec 5, 2024
7747f79
slots props types
JCQuintas Dec 5, 2024
3a8a851
initial consumeslots
JCQuintas Dec 5, 2024
babb6dd
consumelots work
JCQuintas Dec 5, 2024
e3f534c
Make consumeSlots handle forwardRef automatically
JCQuintas Dec 5, 2024
51b7151
add docs and debugging
JCQuintas Dec 5, 2024
4034668
fix props
JCQuintas Dec 5, 2024
8222aed
scripts
JCQuintas Dec 5, 2024
befbb43
improve exports
JCQuintas Dec 5, 2024
c660ba3
label proptypes
JCQuintas Dec 5, 2024
12309ef
Merge commit 'e91b49f8ff1eee038aafdf9eb841632c22083e07' into html-def…
JCQuintas Dec 6, 2024
9720d3d
remove unnecessary "gap" props
JCQuintas Dec 6, 2024
f943eaf
Merge branch 'master' into html-default-legend
JCQuintas Dec 6, 2024
dad2327
Allow setting label mark from series
JCQuintas Dec 6, 2024
92cfd16
ignore proptypes inference on string object
JCQuintas Dec 6, 2024
ca8762e
fix custom string issue
JCQuintas Dec 6, 2024
6ba0219
add gradient label
JCQuintas Dec 9, 2024
245ef36
add conformance tests
JCQuintas Dec 9, 2024
a7f2dfb
Merge commit '7eccbd00caafa6911f8ae3f0a3318614cdc02eaf' into html-def…
JCQuintas Dec 9, 2024
81855a7
fix packagelock
JCQuintas Dec 9, 2024
986d94d
charts html legend
JCQuintas Dec 9, 2024
3a60f62
ignore scripts
JCQuintas Dec 9, 2024
7f3113c
install missing package
JCQuintas Dec 9, 2024
8dae344
Fix eslint
JCQuintas Dec 9, 2024
11a9f05
fix proptypes
JCQuintas Dec 9, 2024
f6c7c4c
add to exports
JCQuintas Dec 9, 2024
84fc162
fix tests
JCQuintas Dec 9, 2024
1ee30cb
Apply suggestions from code review
JCQuintas Dec 10, 2024
dbfb95f
Merge commit '15625a52fe69f8a2c7dd57d0e0af56b179a5a6e7' into html-labels
JCQuintas Dec 10, 2024
0d4524d
fix sizes
JCQuintas Dec 10, 2024
e62716a
use single gradient for column direction
JCQuintas Dec 10, 2024
bd9acfa
remove labelStyle
JCQuintas Dec 10, 2024
f4c97e0
remove unnecessary wide type
JCQuintas Dec 10, 2024
b87353a
Merge commit 'f4c97e096344ad08e756a772b8774da5a8446621' into html-def…
JCQuintas Dec 10, 2024
b95365d
remove labelStyle
JCQuintas Dec 10, 2024
7f305e2
remove unneeded prop
JCQuintas Dec 11, 2024
6707594
remove unneeded props
JCQuintas Dec 11, 2024
fbbbed6
Merge commit '6707594d709a2e1c48713696dbd4677281f3b042' into html-def…
JCQuintas Dec 11, 2024
4213d3b
Remove removed props
JCQuintas Dec 11, 2024
abd0a54
Refactor ChartsLegend and consumeSlots for improved ownerState handling
JCQuintas Dec 11, 2024
1656a23
remove indexes
JCQuintas Dec 11, 2024
3b34b6d
fix issues with deleting index
JCQuintas Dec 11, 2024
1fb08dc
Merge branch 'master' into html-labels
JCQuintas Dec 11, 2024
ca98194
fix proptypes
JCQuintas Dec 11, 2024
bb0133b
add continuous color start
JCQuintas Dec 11, 2024
312474d
label to span
JCQuintas Dec 11, 2024
5788e4d
remove props from label gradient
JCQuintas Dec 11, 2024
437f099
add mask class
JCQuintas Dec 11, 2024
ea8a414
Merge commit '437f0994d3727fca983de72c9a25c81ce06ad5f0' into html-def…
JCQuintas Dec 11, 2024
ea02081
Revert "remove indexes"
JCQuintas Dec 11, 2024
d1253c4
Revert "fix issues with deleting index"
JCQuintas Dec 11, 2024
101926e
use ul/li for legend/items
JCQuintas Dec 11, 2024
9cbf0bd
Continuous color work
JCQuintas Dec 11, 2024
436b169
allow reverting/rotating label gradient
JCQuintas Dec 11, 2024
df8b4fc
Merge commit '436b169c887bb836d90598fb74b8b3d1e0657ed1' into html-def…
JCQuintas Dec 11, 2024
85dca92
remove legend placement prop
JCQuintas Dec 11, 2024
b6c745c
continuous color horizontal
JCQuintas Dec 11, 2024
fdad3d3
Merge commit '99ce15ceddafb5455c4816cfd8baeb63107b47f5' into html-def…
JCQuintas Dec 12, 2024
4184345
continuous color grid
JCQuintas Dec 12, 2024
af71ceb
add tests
JCQuintas Dec 12, 2024
c76bde3
fix tests
JCQuintas Dec 12, 2024
b00c2ea
remove "classkey" types
JCQuintas Dec 12, 2024
96442be
add discrete color legend
JCQuintas Dec 12, 2024
a979388
add tests for discrete color legend
JCQuintas Dec 12, 2024
07c3e7c
replace grid
JCQuintas Dec 12, 2024
bf5f6b8
refactor: rename continuous color legend types for consistency
JCQuintas Dec 12, 2024
304ec7c
refactor: rename DiscreteColorLegend to PiecewiseColorLegend for clarity
JCQuintas Dec 12, 2024
81d1da9
get data from piecewise axis
JCQuintas Dec 12, 2024
3e1d99f
rename items to display
JCQuintas Dec 12, 2024
613f397
Add click listener
JCQuintas Dec 12, 2024
d031b0b
improve click handling
JCQuintas Dec 12, 2024
ba2b42f
refactor: replace default label formatter with piecewiseColorDefaultL…
JCQuintas Dec 12, 2024
2aca38b
row/column to horizontal/vertical
JCQuintas Dec 12, 2024
11166c0
missed rename
JCQuintas Dec 12, 2024
485b5c1
auto generate gradients
JCQuintas Dec 13, 2024
924ed95
fix jsdoc
JCQuintas Dec 13, 2024
2924cfe
format
JCQuintas Dec 13, 2024
95c7d55
impro default
JCQuintas Dec 13, 2024
8ee7afd
proptypes
JCQuintas Dec 13, 2024
6afcb28
proptypes
JCQuintas Dec 13, 2024
7482c9f
proptypes
JCQuintas Dec 13, 2024
079ce99
rename folder to be default
JCQuintas Dec 13, 2024
79da08a
fix type issues from replacing defaults
JCQuintas Dec 13, 2024
e2768c1
replace chartcontainer with the constituting parts
JCQuintas Dec 13, 2024
cb56821
test wrapper for charts
JCQuintas Dec 13, 2024
75ef9c2
Merge branch 'master' into html-default-legend
JCQuintas Dec 13, 2024
4f816e2
revert script change
JCQuintas Dec 13, 2024
01ce1d7
invert legend position
JCQuintas Dec 13, 2024
d518fd4
remove unnecessary blank line in ChartsLegend component
JCQuintas Dec 13, 2024
8cb3edc
Merge branch 'master' into html-default-legend
JCQuintas Dec 13, 2024
49cacce
fix flex
JCQuintas Dec 13, 2024
3f84155
Remove margins
JCQuintas Dec 16, 2024
c3d65f6
Add positioning types
JCQuintas Dec 16, 2024
5698493
Refactor button styles in PiecewiseColorLegend component
JCQuintas Dec 16, 2024
fe8241e
use wrapper to position legends
JCQuintas Dec 16, 2024
90072b6
Merge branch 'master' into html-default-legend
JCQuintas Dec 16, 2024
c420953
fix types and refs
JCQuintas Dec 16, 2024
5557f98
update docs to not break
JCQuintas Dec 16, 2024
eacdb63
classes
JCQuintas Dec 16, 2024
72136d6
fix piecewise styling
JCQuintas Dec 16, 2024
3a87590
move charts legend position
JCQuintas Dec 16, 2024
b25f715
fix piecewise interactive demo
JCQuintas Dec 16, 2024
dd1ef6c
Allow thickness on gradient
JCQuintas Dec 16, 2024
c73083d
Fix continuous color demo
JCQuintas Dec 16, 2024
146fe36
fix wrapper
JCQuintas Dec 16, 2024
28bd3c7
legend demos styling
JCQuintas Dec 16, 2024
268cd87
Move label styling to root so it is easier to style
JCQuintas Dec 16, 2024
72e52d0
improve alignment
JCQuintas Dec 16, 2024
a28c63a
fix button styling
JCQuintas Dec 18, 2024
259ac60
fix LegendTextStyling demo
JCQuintas Dec 18, 2024
97caa2d
fix LegendPositionNoSnap
JCQuintas Dec 18, 2024
2ced233
fix legend dimension no snap
JCQuintas Dec 18, 2024
4ef114f
improve legend docs
JCQuintas Dec 18, 2024
e7b5861
scripts
JCQuintas Dec 18, 2024
81b620d
formatting
JCQuintas Dec 18, 2024
96ed9f2
scripts
JCQuintas Dec 18, 2024
9624e68
Merge branch 'master' into html-default-legend
JCQuintas Dec 18, 2024
59ddbf2
fix pro packages
JCQuintas Dec 18, 2024
dfdc840
remove unused
JCQuintas Dec 19, 2024
38f8cb5
scripts
JCQuintas Dec 19, 2024
aff9404
add lib back
JCQuintas Dec 19, 2024
e1544f8
Revert "fix types and refs"
JCQuintas Dec 19, 2024
7b677a2
fix consumers
JCQuintas Dec 19, 2024
9a117ad
decrease default top margin
JCQuintas Dec 19, 2024
ecb8465
skip themedefaultprops for charts
JCQuintas Dec 19, 2024
01cd40f
Merge branch 'master' into html-default-legend
JCQuintas Dec 19, 2024
42bba84
revert margin change
JCQuintas Dec 19, 2024
ed1aab4
fix lint
JCQuintas Dec 19, 2024
77c9cc9
scripts
JCQuintas Dec 19, 2024
549a598
fix types
JCQuintas Dec 19, 2024
3839883
fix test
JCQuintas Dec 19, 2024
cb46278
Merge branch 'master' into html-default-legend
JCQuintas Dec 19, 2024
cd6fca3
fix scrollable
JCQuintas Dec 19, 2024
17eb236
fix pie sizes
JCQuintas Dec 20, 2024
63c2200
improve demos
JCQuintas Dec 22, 2024
b7545de
Merge branch 'master' into html-default-legend
JCQuintas Dec 23, 2024
6f16789
make margins adapt to legend
JCQuintas Dec 23, 2024
6c3eb28
scripts
JCQuintas Dec 23, 2024
32fbf8d
scripts
JCQuintas Dec 23, 2024
3302005
fix sizing when there are no labels to display
JCQuintas Dec 23, 2024
9f9b8b3
calculate margins when props are defined
JCQuintas Dec 23, 2024
6d2668d
Merge branch 'master' into html-default-legend
JCQuintas Dec 23, 2024
7235d72
fix small demos
JCQuintas Dec 23, 2024
4d12df9
Merge commit '3ead5039e6bd2ba43d4ae1f7203e0ace92478530' into html-def…
JCQuintas Dec 30, 2024
ddbd93e
[core] Update RenderFunction type to use React.JSX.Element
JCQuintas Dec 30, 2024
a44f3e9
codemod for breaking change of direction prop
JCQuintas Dec 30, 2024
44f1d66
Update RenderFunction type to use React.ElementType
JCQuintas Dec 30, 2024
5c8141c
improve html legends demo
JCQuintas Dec 30, 2024
85fae5b
Enhance legend documentation with customization details and HTML comp…
JCQuintas Dec 30, 2024
c90fe2c
Merge branch 'master' into html-default-legend
JCQuintas Dec 30, 2024
cd0ca2f
fix types
JCQuintas Dec 30, 2024
8551280
direction migration
JCQuintas Dec 30, 2024
bb16c55
Update legend direction prop in migration charts documentation
JCQuintas Dec 30, 2024
6a31260
Merge commit 'd85fff19138b109a8d81655d55de62dbca2c6065' into html-def…
JCQuintas Jan 2, 2025
28a72ad
Apply suggestions from code review
JCQuintas Jan 7, 2025
e1efe56
min suggestion
JCQuintas Jan 6, 2025
2e7f890
scripts
JCQuintas Jan 7, 2025
4bf57ef
Update docs/data/charts/legend/LegendMarkTypeNoSnap.js
JCQuintas Jan 7, 2025
aa69d7e
extremes suggestion
JCQuintas Jan 7, 2025
3bd6446
Merge commit 'cad579c88e729ceec526d7bbdb9c893a2d4b1646' into html-def…
JCQuintas Jan 7, 2025
a3df7a2
Revert "extremes suggestion"
JCQuintas Jan 7, 2025
4c644ba
add legend position demo
JCQuintas Jan 7, 2025
3ea559d
simplify api with start/end instead of above/below/left/right
JCQuintas Jan 7, 2025
65bb3d1
simplify chartslabel
JCQuintas Jan 7, 2025
b036fe1
revert wrapper
JCQuintas Jan 7, 2025
8fcc018
add bc to migration
JCQuintas Jan 7, 2025
8f14702
reduce legend component dimensions to improve layout
JCQuintas Jan 7, 2025
701a579
Merge branch 'master' into html-default-legend
JCQuintas Jan 7, 2025
4b58d39
fix prettier
JCQuintas Jan 7, 2025
63e73bc
fix style
JCQuintas Jan 7, 2025
2d4e740
fix browser tests
JCQuintas Jan 7, 2025
6015932
fix api
JCQuintas Jan 7, 2025
54ea6f4
reverseGradient to reverse
JCQuintas Jan 8, 2025
5665712
lineheight 100%
JCQuintas Jan 8, 2025
c44ddb8
skip exporting label elements
JCQuintas Jan 8, 2025
31d039b
fix piecewise and add examples to prevent future issues
JCQuintas Jan 8, 2025
e7c9c3c
Merge branch 'master' into html-default-legend
JCQuintas Jan 8, 2025
6d00e49
scripts
JCQuintas Jan 8, 2025
b8f50d0
remove removed apis
JCQuintas Jan 8, 2025
fddecca
fix tests
JCQuintas Jan 8, 2025
a6b98ce
fix ts error
JCQuintas Jan 8, 2025
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
1 change: 0 additions & 1 deletion docs/data/charts/bars/BarGapNoSnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function BarGapNoSnap() {
<BarChart
dataset={balanceSheet}
series={series}
width={500}
height={300}
margin={{ top: 15 }}
xAxis={[
Expand Down
1 change: 1 addition & 0 deletions docs/data/charts/bars/BarsDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const chartSetting = {
],
width: 500,
height: 300,
margin: { left: 60 },
sx: {
[`.${axisClasses.left} .${axisClasses.label}`]: {
transform: 'translate(-20px, 0)',
Expand Down
1 change: 1 addition & 0 deletions docs/data/charts/bars/BarsDataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const chartSetting = {
],
width: 500,
height: 300,
margin: { left: 60 },
sx: {
[`.${axisClasses.left} .${axisClasses.label}`]: {
transform: 'translate(-20px, 0)',
Expand Down
3 changes: 1 addition & 2 deletions docs/data/charts/bars/BorderRadius.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ const chartSettingsH = {
},
slotProps: {
legend: {
direction: 'row',
direction: 'horizontal',
position: { vertical: 'bottom', horizontal: 'middle' },
padding: -5,
},
},
};
Expand Down
3 changes: 1 addition & 2 deletions docs/data/charts/bars/BorderRadius.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ const chartSettingsH: Partial<BarChartProps> = {
},
slotProps: {
legend: {
direction: 'row',
direction: 'horizontal',
position: { vertical: 'bottom', horizontal: 'middle' },
padding: -5,
},
},
};
Expand Down
11 changes: 8 additions & 3 deletions docs/data/charts/bars/StackBars.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ export default function StackBars() {
{ dataKey: 'treas', stack: 'equity' },
])}
xAxis={[{ scaleType: 'band', dataKey: 'year' }]}
hideLegend
width={600}
height={350}
{...config}
/>
);
}

const config = {
width: 600,
height: 350,
margin: { left: 70 },
hideLegend: true,
};
13 changes: 9 additions & 4 deletions docs/data/charts/bars/StackBars.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { BarChart } from '@mui/x-charts/BarChart';
import { BarChart, BarChartProps } from '@mui/x-charts/BarChart';
import { addLabels, balanceSheet } from './netflixsBalanceSheet';

export default function StackBars() {
Expand All @@ -16,9 +16,14 @@ export default function StackBars() {
{ dataKey: 'treas', stack: 'equity' },
])}
xAxis={[{ scaleType: 'band', dataKey: 'year' }]}
hideLegend
width={600}
height={350}
{...config}
/>
);
}

const config: Partial<BarChartProps> = {
width: 600,
height: 350,
margin: { left: 70 },
hideLegend: true,
};
4 changes: 1 addition & 3 deletions docs/data/charts/bars/StackBars.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@
{ dataKey: 'treas', stack: 'equity' },
])}
xAxis={[{ scaleType: 'band', dataKey: 'year' }]}
hideLegend
width={600}
height={350}
{...config}
/>
6 changes: 3 additions & 3 deletions docs/data/charts/components/HtmlLegend.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { unstable_useBarSeries } from '@mui/x-charts/hooks';
import { useLegend } from '@mui/x-charts/hooks';
import { ChartDataProvider } from '@mui/x-charts/context';
import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
import { BarPlot } from '@mui/x-charts/BarChart';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';

function MyCustomLegend() {
const s = unstable_useBarSeries();
const { items } = useLegend();
return (
<table
style={{
Expand All @@ -17,7 +17,7 @@ function MyCustomLegend() {
}}
>
<tbody>
{Object.values(s?.series ?? []).map((v) => {
{items.map((v) => {
return (
<tr key={v.id}>
<td aria-hidden>
Expand Down
6 changes: 3 additions & 3 deletions docs/data/charts/components/HtmlLegend.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { unstable_useBarSeries } from '@mui/x-charts/hooks';
import { useLegend } from '@mui/x-charts/hooks';
import { ChartDataProvider } from '@mui/x-charts/context';
import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
import { BarPlot } from '@mui/x-charts/BarChart';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';

function MyCustomLegend() {
const s = unstable_useBarSeries();
const { items } = useLegend();
return (
<table
style={{
Expand All @@ -17,7 +17,7 @@ function MyCustomLegend() {
}}
>
<tbody>
{Object.values(s?.series ?? []).map((v) => {
{items.map((v) => {
return (
<tr key={v.id}>
<td aria-hidden>
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/components/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ With the introduction of the `ChartDataProvider` in v8, the chart data can be ac
This allows you to create HTML components that interact with the charts data.

In the next example, notice that `MyCustomLegend` component displays the series names and colors.
This creates an html `table` element, which handles long series names better than the default legend.
This creates an html `table` element, which can be customized in any way.

{{"demo": "HtmlLegend.js"}}

:::warning
Note that the HTML components are not part of the SVG hierarchy.
Hence, they should be:

- Outside the `<ChartsSurface />` component to avoid mixing HTAM and SVG.
- Outside the `<ChartsSurface />` component to avoid mixing HTML and SVG.
- Inside the `<ChartDataProvider />` component to get access to the data.

:::
1 change: 1 addition & 0 deletions docs/data/charts/heatmap/ColorConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function ColorConfig() {
xAxis={[{ data: xData }]}
yAxis={[{ data: yData }]}
series={[{ data }]}
margin={{ left: 70 }}
zAxis={[
{
min: 20,
Expand Down
1 change: 1 addition & 0 deletions docs/data/charts/heatmap/ColorConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default function ColorConfig() {
xAxis={[{ data: xData }]}
yAxis={[{ data: yData }]}
series={[{ data }]}
margin={{ left: 70 }}
zAxis={[
{
min: 20,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/label/PieLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export default function PieLabel() {
}

const props = {
width: 500,
width: 200,
height: 200,
};
2 changes: 1 addition & 1 deletion docs/data/charts/label/PieLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export default function PieLabel() {
}

const props = {
width: 500,
width: 200,
height: 200,
};
22 changes: 13 additions & 9 deletions docs/data/charts/legend/BasicColorLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import Typography from '@mui/material/Typography';
import { LineChart } from '@mui/x-charts/LineChart';
import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine';
import { PiecewiseColorLegend } from '@mui/x-charts/ChartsLegend';
import Stack from '@mui/material/Stack';
import { dataset } from './tempAnomaly';

export default function BasicColorLegend() {
return (
<div style={{ width: '100%' }}>
<Stack width={'100%'}>
JCQuintas marked this conversation as resolved.
Show resolved Hide resolved
<Typography variant="body1">
Global temperature anomaly relative to 1961-1990 average
</Typography>
Expand Down Expand Up @@ -43,16 +44,19 @@ export default function BasicColorLegend() {
]}
grid={{ horizontal: true }}
height={300}
margin={{ top: 30, right: 150 }}
hideLegend
margin={{ top: 20, right: 20 }}
slotProps={{
legend: {
axisDirection: 'x',
direction: 'vertical',
},
}}
slots={{
legend: PiecewiseColorLegend,
}}
>
<PiecewiseColorLegend
axisDirection="x"
position={{ vertical: 'top', horizontal: 'right' }}
direction="column"
/>
<ChartsReferenceLine y={0} />
</LineChart>
</div>
</Stack>
);
}
22 changes: 13 additions & 9 deletions docs/data/charts/legend/BasicColorLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import Typography from '@mui/material/Typography';
import { LineChart } from '@mui/x-charts/LineChart';
import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine';
import { PiecewiseColorLegend } from '@mui/x-charts/ChartsLegend';
import Stack from '@mui/material/Stack';
import { dataset } from './tempAnomaly';

export default function BasicColorLegend() {
return (
<div style={{ width: '100%' }}>
<Stack width={'100%'}>
<Typography variant="body1">
Global temperature anomaly relative to 1961-1990 average
</Typography>
Expand Down Expand Up @@ -43,16 +44,19 @@ export default function BasicColorLegend() {
]}
grid={{ horizontal: true }}
height={300}
margin={{ top: 30, right: 150 }}
hideLegend
margin={{ top: 20, right: 20 }}
slotProps={{
legend: {
axisDirection: 'x',
direction: 'vertical',
},
}}
slots={{
legend: PiecewiseColorLegend,
}}
>
<PiecewiseColorLegend
axisDirection="x"
position={{ vertical: 'top', horizontal: 'right' }}
direction="column"
/>
<ChartsReferenceLine y={0} />
</LineChart>
</div>
</Stack>
);
}
Loading
Loading