Charts - Styling
This page groups topics about charts customistion.
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 charts layout is the drawing area which corresponds to the space available to represent data.
This space can be fined 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 let more space for your axis ticks or reduce them to provide more space for the data.
CSS
Since the library relies on SVG for rendering, you can customize them as you do with other MUI components with CSS overriding.
Chart components accept the sx
props.
And you can target any sub elements with its class name.