# @google-web-components/google-chart

> Encapsulates Google Charts into a web component

Latest version **5.1.0** (published 2024-05-06) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @google-web-components/google-chart
pnpm add @google-web-components/google-chart
yarn add @google-web-components/google-chart
bun add @google-web-components/google-chart
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2024-05-06 |
| First published | 2018-12-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 87.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 369 |
| Maintainers | google-wombot |
| Keywords | web-component, web-components, polymer, lit-element, chart, charts, google-visualization, google |

## Links

- npm: https://www.npmjs.com/package/@google-web-components/google-chart
- Repository: https://github.com/GoogleWebComponents/google-chart
- Homepage: https://googlewebcomponents.github.io/google-chart
- Issues: https://github.com/GoogleWebComponents/google-chart/issues
- npm.io page: https://npm.io/package/@google-web-components/google-chart

## Dependencies (2)

- [lit](https://npm.io/package/lit.md) ^3.1.3
- [safevalues](https://npm.io/package/safevalues.md) ^0.5.2

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 5.1.0 (latest) — 2024-05-06
- 5.0.5 — 2023-09-05
- 5.0.4 — 2023-07-20
- 5.0.3 — 2023-02-10
- 5.0.2 — 2022-03-25
- 5.0.1 — 2021-12-16
- 5.0.0 — 2021-10-20
- 4.0.2 — 2021-01-25
- 4.0.1 — 2020-12-01
- 4.0.0 — 2020-07-10
- 3.4.0 — 2020-03-13
- 3.3.1 — 2020-01-23
- 3.3.0 — 2019-11-09
- 3.2.1 — 2019-11-03
- 3.2.0 — 2019-10-04
- … 10 more at https://npm.io/package/@google-web-components/google-chart/versions

## README

# google-chart

[Google Charts API](https://developers.google.com/chart/) web components.

See: [Documentation](https://www.webcomponents.org/element/@google-web-components/google-chart)

[![Published on NPM](https://img.shields.io/npm/v/@google-web-components/google-chart.svg)](https://www.npmjs.com/package/@google-web-components/google-chart) [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/@google-web-components/google-chart)

## Usage

### Installation

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

### In HTML file

```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>
```

### In a LitElement

```typescript
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>
    `;
  }
}
```

### In a Polymer 3 element

```javascript
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);
```

### More usage examples

See examples in the demo or try this live [JS bin](https://jsbin.com/zitotejimi/edit?html,output).

## Uprading from 3.x

The component has been migrated to LitElement and uses TypeScript now. This migration introduced two breaking changes.

### Removed Polymer-specific `selection-changed` event

The Polymer-specific `selection-changed` event commonly used for 2-way bindings has been removed.
There were previously two events for observing chart selection changes: `google-chart-select` and the Polymer-generated `selection-changed`.
For consistency with other events (e.g. `google-chart-ready`), we keep only `google-chart-select`.

Polymer components using this feature must be updated to explicitly name the selection event ([details](https://polymer-library.polymer-project.org/3.0/docs/devguide/data-binding#two-way-native)).
In the example below, note the addition of `::google-chart-select`.

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

LitElement components using the `selection-changed` event must be updated in a similar fashion:

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

### Removed `google-chart-loader` component

Its functionality can be imported from the `loader.js` module:

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

or you may instead choose to use `google.visualization.ChartWrapper` directly ([example](https://developers.google.com/chart/interactive/docs/reference#chartwrapper-class)).

## Contributing

Instructions for running the tests and demo locally:

### Installation

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

### Running the demo locally

```sh
npm start
```

The browser will open automatically.

### Running the tests

```sh
npm test
```

---
_Source: https://npm.io/package/@google-web-components/google-chart · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
