React Chart - Show and Hide a Series

The Chart provides an API for showing and hiding a series at runtime. The most common use-case for this API is to show or hide a series when a user clicks the chart legend. To implement this scenario, you need to handle the legendClick event in the following manner. The isVisible(), hide() and show() are methods of the Series object.

App.tsx
  • import React, { useCallback } from 'react';
  • import Chart, { type ChartTypes } from 'devextreme-react/chart';
  •  
  • function App() {
  • const legendClickHandler = useCallback((e: ChartTypes.LegendClickEvent) => {
  • const series = e.target;
  • if (series.isVisible()) {
  • series.hide();
  • } else {
  • series.show();
  • }
  • }, []);
  •  
  • return (
  • <Chart
  • onLegendClick={legendClickHandler}
  • ... >
  • </Chart>
  • );
  • }
  •  
  • export default App;

You can hide a series on component initialization. To do this, assign false to the visible property of the object that configures the series.

App.js
  • import React from 'react';
  • import Chart, {
  • Series
  • } from 'devextreme-react/chart';
  •  
  • export default function App() {
  • return (
  • <Chart ... >
  • <Series visible={false} />
  • </Chart>
  • );
  • }
NOTE
You can hide series to reduce the number of rendered component elements. This can improve Chart performance on large datasets. For more information on how to improve component performance, refer to the following topic: Enhance Performance on Large Datasets.
See Also