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.

Not able to use toggleSeries with next js application

See original GitHub issue

I want to toggleSeries data of a chart in my next js application. I am trying to use that method in 2 different ways, but none of them is working. I will show you the error i am getting with both these methods differently. Please help me with a solution.

Method 1:

import ApexCharts from 'apexcharts';

toggleSeries = (seriesName) => {
  ApexCharts.exec('myChartId', 'toggleSeries', 'seriesName');
}

In method 1 there are 2 problems

  1. Most of the time i get window is not defined for ApexCharts
  2. Second, sometimes i get: apexcharts__WEBPACK_IMPORTED_MODULE_9___default.a.exec is not a function/

In order to resolve error: window is not defined I use dynamic import as i use dynamic import for react-apexcharts see below Method 2:

const ApexCharts = dynamic(() => import('apexcharts'), { ssr: false });

toggleSeries = (seriesName) => {
  ApexCharts.exec('myChartId', 'toggleSeries', 'seriesName');
}

In method 2 it says ApexCharts.exec is not a function.

Please help me with the solution for this

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:12

github_iconTop GitHub Comments

60reactions
mitsamphancommented, Jan 22, 2021

@hbole

Use react-apexcharts apexcharts package and solve with dynamic import in next.js

import React, { useState, useEffect } from "react";
import dynamic from "next/dynamic";
const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });

export default function ChartSample() {
  const [dataSample, setDataSample] = useState({
    options: {
      chart: {
        id: "basic-bar",
      },
      xaxis: {
        categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998],
      },
    },
    series: [
      {
        name: "series-1",
        data: [30, 40, 45, 50, 49, 60, 70, 91],
      },
    ],
  });

  return (
    <div>
      <Chart
        options={dataSample.options}
        series={dataSample.series}
        type="line"
        width="500"
      />
    </div>
  );
}

and call component <ChartSample />

5reactions
alex-r89commented, Aug 19, 2021

Hi,

Apologies, I know this is closed but no solution here works in terms of toggling a series with an external button for me.

I have tried the method by @MisaelMa , but I get the error ApexCharts.exec is not a function after importing the chart component and clicking the button.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started | Next.js
Get started with Next.js in the official documentation, and learn more about all our features!
Read more >
Advanced Features: Custom `App` - Next.js
Note: Next.js 13 introduces the app/ directory (beta). This new directory has support for layouts, nested routes, and uses Server Components by default....
Read more >
Basic Features: Handling Scripts - Next.js
Offloading Scripts To A Web Worker (experimental) ... Note: The worker strategy is not yet stable and does not yet work with the...
Read more >
next.config.js: Introduction
js module, not a JSON file. It gets used by the Next.js server and build phases, and it's not included in the browser...
Read more >
Advanced Features: Custom Server - Next.js
Start a Next.js app programmatically using a custom server. ... have an existing backend, you can still use it with Next.js (this is...
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