Charts - Styling
This page groups topics about charts customization.
Colors
Series color
Series accepts a property color
which is the base color used to render its components.
<LineChart series={[{ ..., color: '#fdb462'}]} />
Color palette
Charts come with built-in color palettes to automatically assign colors to series. If a particular series lacks a color prop, the chart will default to assigning a color based on the series' index.
You can set a custom color palette by using the prop colors
on chart components (or <ChartContainer />
if you are using composition).
This prop takes an array of colors, or callback whose input is the theme's mode ('dark'
or 'light'
) and returns the array of colors.
Provided palettes
The library includes three palettes.
blueberryTwilight
Custom palettes
Those palettes can also be generated by using d3-scale-chromatic. Or any color manipulation library you like.
Here is an example of the d3 Categorical color palette.
Category10
Styling
Size
By default, charts adapt their sizing to fill their parent element.
However, you can modify this behavior by providing height
and/or width
props.
Those will fix the chart's size to the given value (in px).
Placement
At the core of chart layout is the drawing area which corresponds to the space available to represent data.
This space can be defined with the margin
prop and its properties top
, bottom
, left
, and right
.
Those values define the space between the SVG border and the drawing area.
You might want to modify those values to leave more space for your axis ticks or reduce them to provide more space for the data.
import { BarChart } from '@mui/x-charts/BarChart';
<BarChart
// ...
margin={{
left: undefined,
right: undefined,
top: undefined,
bottom: undefined,
}}
/>