How to render the React Chart in dark theme?
This article explains how to render the React Chart in dark theme.
Customize to dark theme
By default, the React chart renders with the Material Light theme. You can easily customize it to the Dark theme by using the theme property in the chart.
In the following code example, the chart renders with the Material3 dark theme.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, LineSeries,
Category, DataLabel } from '@syncfusion/ej2-react-charts';
const Line = () => {
return (
<chartcomponent id="charts" primaryxaxis="{{" valuetype:="" 'double'="" }}="" primaryyaxis="{{" labelformat:="" '{value}%',="" title:="" 'efficiency',="" minimum:="" 20,="" maximum:="" 40,="" interval:="" 5="" title="Efficiency of oil-fired power production" theme="Material3Dark">
<inject services="{[LineSeries," category,="" datalabel]}="">
<seriescollectiondirective>
<seriesdirective datasource="{data}" xname="x" yname="y" type="Line" width="{2}" marker="{{" datalabel:="" {="" visible:="" true="" }="" }}="">
</seriesdirective></seriescollectiondirective>
</inject></chartcomponent>
);
};
export default Line;
const root = createRoot(document.getElementById('sample'));
root.render(<line>);
The following screenshot portrays the results of the code snippet mentioned above.
Screenshot:
Light Theme
Dark Theme
Refer to the working sample for additional details and implementation: View Sample in Stackblitz
Conclusion
We hope you enjoyed learning how to render the React chart in a dark theme using the React chart component.
You can refer to our React Chart feature tour page to learn about its other groundbreaking feature representations and documentation to understand how to quickly get started with configuration specifications. You can also explore our React Chart example to learn how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!