@google-web-components/google-chart

中文文档
5.1.0发布于 2024/05/06Apache-2.0TypeScriptES Module近 30 天下载 2.8万

将 Google 图表封入网络组件

中文使用文档
文档目录13 节
  1. 使用量
  2. 安装
  3. 在 HTML 文件内
  4. 在一个LitElement中
  5. 在多聚体3元素中
  6. 更多使用实例
  7. 从 3.x 恢复
  8. 删除的多聚体特性 selection-changed 事件
  9. 删除 google-chart-loader 组件
  10. 捐款
  11. 安装
  12. 本地运行演示
  13. 运行测试

谷歌图

谷歌图表 API 网络组件.

见: 文档

Published on NPM Published on webcomponents.org

使用量

安装

npm i @google-web-components/google-chart

在 HTML 文件内

<html>
  <head>
    <script type="module">
      import '@google-web-components/google-chart';
    </script>
  </head>
  <body>
    <google-chart data='[["Month", "Days"], ["Jan", 31]]'></google-chart>
  </body>
</html>

在一个LitElement中

import {LitElement, html} from 'lit';
import {customElement} from 'lit/decorators.js';
import '@google-web-components/google-chart';

@customElement('new-element')
export class NewElement extends LitElement {
  render() {
    return html`
      <google-chart data='[["Month", "Days"], ["Jan", 31]]'></google-chart>
    `;
  }
}

在多聚体3元素中

import {PolymerElement, html} from '@polymer/polymer';
import '@google-web-components/google-chart';

class NewElement extends PolymerElement {
  static get template() {
    return html`
      <google-chart data='[["Month", "Days"], ["Jan", 31]]'></google-chart>
    `;
  }
}
customElements.define('new-element', NewElement);

更多使用实例

查看演示中的实例或尝试此实况 联合来文:本。 。 。 .

从 3.x 恢复

该组件已迁移到 LitElement , 现在使用 TypeScript 。 这种迁移带来了两个突破性的变化.

删除的多聚体特性 selection-changed 事件

特定多聚体 selection-changed 用于双向绑定的事件已被删除. 以往有两起观测图表选择变化的事件: google-chart-select 和多聚体产生的 selection-changed。 。 。 . 为了与其他事件保持一致(例如:. google-chart-ready),我们只保留 google-chart-select。 。 。 .

使用此特性的多聚体组件必须更新,以明确命名选择事件(细节) (中文(简体) ). 在下文的例子中,注意到增加了: ::google-chart-select。 。 。 .

- <google-chart selection="{{chartSelection}}"></google-chart>
+ <google-chart selection="{{chartSelection::google-chart-select}}"></google-chart>

使用 selection-changed 事件必须以类似方式更新:

- <google-chart .selection="${chartSelection}" @selection-changed="${reactToChartSelection}"></google-chart>
+ <google-chart .selection="${chartSelection}" @google-chart-select="${reactToChartSelection}"></google-chart>

删除 google-chart-loader 组件

其功能可以从 loader.js 模块 :

import {dataTable, load} from '@google-web-components/google-chart/loader.js';

或者您可以选择使用 google.visualization.ChartWrapper 直接( e)实例) (中文(简体) ).

捐款

本地测试和演示操作指令 :

安装

git clone https://github.com/GoogleWebComponents/google-chart.git
cd google-chart
npm install

本地运行演示

npm start

浏览器会自动打开 .

运行测试

npm test

版本与发布记录

@google-web-components/google-chart 共发布 25 个版本,首次发布于 2018/12/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.1.0latest2024/05/062 年前
5.0.52023/09/063 年前
5.0.42023/07/203 年前
5.0.32023/02/113 年前
5.0.22022/03/254 年前
5.0.12021/12/174 年前

关于 @google-web-components/google-chart 的常见问题

@google-web-components/google-chart 是什么?

将 Google 图表封入网络组件

如何安装 @google-web-components/google-chart?

在项目目录运行 npm install @google-web-components/google-chart,或使用 pnpm add / yarn add / bun add。

@google-web-components/google-chart 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@google-web-components/google-chart 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@google-web-components/google-chart 可以商用吗?

@google-web-components/google-chart 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@google-web-components/google-chart 的下载量有多少?

根据 npm 官方下载统计,@google-web-components/google-chart 在 2026/10/17 – 2026/11/15 这 30 天内被下载 28,426 次,日均约 948 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@google-web-components/google-chart 还在维护吗?

最新版本 5.1.0 发布于 2024/05/06(2 年前);至今共发布 25 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/12/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。