Skip to main content

Themes & Styling

Themes

Victory themes are reusable style configurations that enable you to standardize the appearance of charts across your application. Themes simplify chart development by reducing repetitive styling logic and ensuring visual consistency.

Themes are applied at the chart level and automatically cascade to all child components, such as axes, bars, lines, and legends. Victory provides built-in themes like clean, material and grayscale, but you can also create custom themes to match your branding.

How Themes Work in Victory

Victory themes are essentially JavaScript objects that define styling properties for various chart elements. These theme configurations enable consistent and reusable styling across charts. Each theme configuration variable corresponds to a specific chart element and takes props that define its styles.

Theme configuration variables include:

Each configuration variable takes props specific to its chart element, allowing customization of styles like colors, padding, labels, and more. For detailed information about each variable, refer to the VictoryTheme API page.

When a theme is passed to a chart via the theme prop, the styles from the theme object are applied to the corresponding child components unless they are explicitly overridden by inline props.

Live View
Loading...
Live Editor

Predefined Themes

Victory includes several built-in themes to help you quickly style your charts:

ThemeDescription
VictoryTheme.cleanA minimalist theme with no gridlines or extra styling, perfect for clean and modern visualizations.
VictoryTheme.materialInspired by Google's Material Design, this theme includes bold colors and a structured grid.
VictoryTheme.grayscaleA neutral theme featuring grayscale tones, ideal for muted and professional-looking charts.

Each of these themes can be applied to your Victory components by passing it into the theme prop.

Live View
Loading...
Live Editor

You can also customize these themes or use them as a base to create your own. To build upon a predefined theme, you can extend it using the spread operator:

const extendedTheme = {
...VictoryTheme.material,
axis: {
...VictoryTheme.material.axis,
style: {
...VictoryTheme.material.axis
.style,
tickLabels: {
fill: "#444",
fontSize: 10,
fontStyle: "italic",
},
},
},
};

Creating a Custom Theme

To create a completely custom theme, define a JavaScript object that includes styles for the components you want to theme. You can omit components that use default styling.

Live View
Loading...
Live Editor

To enhance the "Styles" section of the Victory Themes guide, consider incorporating the following detailed explanations and examples:

Styling Individual Components

To customize the appearance of Victory components, you can use the style prop, which accepts an object containing styles for various component elements like data, labels, and parent. For a detailed breakdown of the style options available, refer to the Victory Style Interface.

Example: Customizing Bar and Line Colors

Live View
Loading...
Live Editor

Styling Data

To style individual elements within a dataset, you can include style attributes directly in your data objects and utilize functional styles.

Note: Continuous data components like VictoryLine and VictoryArea render a single SVG element for the entire dataset, so individual styling of data points within these components is not applicable.

Live View
Loading...
Live Editor

Using Gradient Fills

To apply gradient fills to your charts, define a gradient in the SVG defs section and reference it by id in your component's style. Gradients can be used to give continuous charts (i.e. line or area charts) the appearance of discrete data elements and hover states.

Live View
Loading...
Live Editor

Like this project? You'll love working with us.

Contact us to learn more about our full range of services and offerings.

Learn More