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.js
- import React from 'react';
- import Chart from 'devextreme-react/chart';
- class App extends React.Component {
- render() {
- return (
- <Chart
- onLegendClick={this.legendClickHandler}
- ... >
- </Chart>
- );
- }
- legendClickHandler(e) {
- const series = e.target;
- if (series.isVisible()) {
- series.hide();
- } else {
- series.show();
- }
- }
- }
- export default App;
A series can be hidden initially. For 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';
- class App extends React.Component {
- render() {
- return (
- <Chart ... >
- <Series visible={false} />
- </Chart>
- );
- }
- }
- export default App;
See Also
Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.