React Chart - Access a Series Using the API

The Chart exposes the following methods for accessing a series. All of them return one or several objects whose fields and methods are described in the Series section of the API reference.

  • getAllSeries()
    Gets all series of the Chart.

    App.js
    • import React from 'react';
    • import Chart from 'devextreme-react/chart';
    •  
    • class App extends React.Component {
    • constructor(props) {
    • super(props);
    • this.chartRef = React.createRef();
    • }
    • render() {
    • return (
    • <Chart ref={this.chartRef}></Chart>
    • );
    • }
    • get chart() {
    • return this.chartRef.current.instance();
    • }
    • getAllSeries () {
    • return this.chart.getAllSeries();
    • }
    • }
    •  
    • export default App;
  • getSeriesByName(seriesName)
    Gets a series by its name.

    App.js
    • import React from 'react';
    • import Chart from 'devextreme-react/chart';
    •  
    • class App extends React.Component {
    • constructor(props) {
    • super(props);
    • this.chartRef = React.createRef();
    • }
    • render() {
    • return (
    • <Chart ref={this.chartRef}></Chart>
    • );
    • }
    • get chart() {
    • return this.chartRef.current.instance();
    • }
    • getSeriesByName (seriesName) {
    • return this.chart.getSeriesByName(seriesName);
    • }
    • }
    •  
    • export default App;
  • getSeriesByPos(seriesIndex)
    Gets a series by its index in the series array. The index is zero-based.

    App.js
    • import React from 'react';
    • import Chart from 'devextreme-react/chart';
    •  
    • class App extends React.Component {
    • constructor(props) {
    • super(props);
    • this.chartRef = React.createRef();
    • }
    • render() {
    • return (
    • <Chart ref={this.chartRef}></Chart>
    • );
    • }
    • get chart() {
    • return this.chartRef.current.instance();
    • }
    • getSeriesByPos(seriesIndex) {
    • return this.chart.getSeriesByPos(seriesIndex);
    • }
    • }
    •  
    • export default App;

Apart from the API methods, you can access a series in the event handlers. For example, the onSeriesClick event handler gets the clicked series in the argument.

App.js
  • import React from 'react';
  • import Chart from 'devextreme-react/chart';
  •  
  • class App extends React.Component {
  • render() {
  • return (
  • <Chart onSeriesClick={onSeriesClick}>
  • </Chart>
  • );
  • }
  • }
  •  
  • function onSeriesClick (e) {
  • const series = e.target;
  • // ...
  • }
  •  
  • export default App;

Once you get the series, you can access its child points. For further information, refer to the Access a Series Point Using the API topic.

See Also