question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Hooks ApexCharts.exec

See original GitHub issue
export default function ExampleChart({
  data,
  ...props
}) {
  let series = data

  useEffect(() => {
    ApexCharts.exec("example", 'updateSeries', series)  
  }, [series]);

  return (
            <Charts
              options={options}
              series={[]}
              type={"area"}
              height={300}
            />
  );
}

let options = {
   chart: { 
      id: "example",
      group: "example-groups"
   }, 
   ...
}

gives the error TypeError: i.publicMethods is undefined at line ApexCharts.exec("example", 'updateSeries', series). Error is probably because I’m using it incorrectly.

What is the correct way to update series using React Hooks?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

4reactions
thellimistcommented, Sep 24, 2020

This solution works

...
import Charts from "react-apexcharts";
import ApexCharts from 'apexcharts';

export default function Chart({ 
  newSeries,
  newOptions,
  ...props 
}) {

  useDeepCompareEffect(() => { // or useEffect
    ApexCharts.exec(`Chart:${id}`, 'updateSeries' , newSeries);
    ApexCharts.exec(`Chart:${id}`, 'updateOptions' , newOptions, false, true, true);
  },[newSeries, newOptions]);

  return (

            <Charts
              options={newOptions}
              series={newSeries}
              type='line'
              height='350'
            />
  );
}
2reactions
gfortainecommented, Apr 1, 2020

@thellimist It looks like that it works fine : https://codesandbox.io/s/react-basic-example-7xce1

However, it seems that your example is a bit of nonsense. What is the point of updating the series by calling the method updateSeries in a useEffect Hook ? If you update the props data in your example, the Chart will also update with the new props…

<Chart options={options} series={series} type="area" width="300" />

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apexcharts With Function Component #3 Tutorial - YouTube
Render Dynamic Data Using An API In Apexcharts with hooks | Apexcharts with function #4 Tutorial · React Hook useRef and forwarding refs...
Read more >
React Apex Chart Using Hooks - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
A React Chart wrapper for ApexCharts.js
React -ApexCharts is a wrapper component for ApexCharts ready to be integrated into your react.js application to create stunning React Charts.
Read more >
Charting in React with ApexCharts - LogRocket Blog
Charting in React with ApexCharts · Responsiveness: Your charts will scale according to the viewing device. · Annotations: Apex also allows you to ......
Read more >
React ApexCharts update chart with interval - Stack Overflow
You are passing no dependencies to useEffect. This makes it run on every render which makes your charts redraw very often.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found