如何在 Angular 7 中使用`apexchart`?

问题描述 投票:0回答:3

如何在 Angular 7 中使用

apexchart
?有人可以在打字稿中实现它吗?我正在 Angular 中搜索它的打字稿实现,但我无法做到。我的 Angular 版本是 7.2.4。

angular typescript apexcharts
3个回答
0
投票

npm 上似乎有 Apexcharts 的包装器。 欲了解更多信息:https://github.com/apexcharts/ng-apexcharts

使用示例:https://ngapexcharts-demo.stackblitz.io/


0
投票

根据 Apexcharts 文档 https://apexcharts.com/docs/installation

首先:你需要安装包:npm i apexcharts

再次根据文档,您需要定义要使用的 ApexCharts 类型:

import ApexCharts from 'apexcharts'

如果这对您有用,请继续。但如果您收到“...没有默认导出”错误,则需要按如下方式定义:

import ApexCharts from 'apexcharts/dist/apexcharts.common.js'

然后你需要一个 html 元素来绑定你的图表:

最后以正确的方法创建图表选项并按如下方式呈现:

const options = {
  chart: {
    height: 300,
    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]
  }
}

const chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();

Your chart will be looks like this image


0
投票

您可以在以下链接中找到使用 Angular 实现 ApexCharts 的正确步骤。 https://apexcharts.com/docs/angular-charts/

请参阅此博客,了解为 ApexCharts 设置项目的详细信息,您还可以看到一个生成不同类型图表的示例。

中型博客.

© www.soinside.com 2019 - 2024. All rights reserved.