Skip to content

Not able to use ApexCharts.js as web-component #1332

@ulshv

Description

@ulshv

Great lib! Anyways, I'm not able to use it in new project which is based on web-components with LitElement. It's throwing this error:

DetectElementResize.js:79 Uncaught (in promise) TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
    at push../node_modules/apexcharts/src/utils/DetectElementResize.js.window.addResizeListener (DetectElementResize.js:79)
    at apexcharts.js:113
    at new Promise (<anonymous>)
    at ApexCharts.render (apexcharts.js:90)
    at HTMLElement.<anonymous> (hs-line-chart.ts:29)

Code example:

import { LitElement, html } from 'lit-element';
import ApexCharts from 'apexcharts';

class LineChart extends LitElement {
  static get is() {
    return 'line-chart';
  }

  async renderChart() {
    await this.updateComplete;

    var options = {
      theme: 'dark',
      chart: {
        type: 'line',
      },
      series: [{
        name: 'sales',
        data: [30,40,35,50,49,60,70,91,125]
      }],
      xaxis: {
        categories: [1991,1992,1993,1994,1995,1996,1997, 1998,1999]
      }
    }

    var chart = new ApexCharts(this.shadowRoot.querySelector("#container"), options);

    chart.render();
  }

  render() {
    return html`<div id="container"></div>`;
  }
}

window.customElements.define(LineChart.is, LineChart);

export default LineChart;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions