# use-amcharts

> React hook for working with Amcharts 4 library. Supports TypeScript type-inference and automatically destroys on component unmount.

Latest version **1.0.2** (published 2021-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-amcharts
pnpm add use-amcharts
yarn add use-amcharts
bun add use-amcharts
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-01-10 |
| First published | 2021-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Egor Gorbachev |
| Maintainers | kubk |

## Links

- npm: https://www.npmjs.com/package/use-amcharts
- npm.io page: https://npm.io/package/use-amcharts

## Recent versions

- 1.0.2 (latest) — 2021-01-10
- 1.0.1 — 2021-01-10
- 1.0.0 — 2021-01-10
- 0.1.0 — 2021-01-10

## README

# use-amcharts

React hook for working with Amcharts 4 library. Supports TypeScript type-inference and automatically destroys on component unmount.

### Installation

`npm i use-amcharts`

### Usage

```tsx
let data = [];
let visits = 10;

for (let i = 1; i < 366; i++) {
  visits += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 10);
  data.push({ date: new Date(2018, 0, i), name: "name" + i, value: visits });
}

export const Chart = () => {
  const { amchartsElRef } = useAmcharts(am4charts.XYChart, (chart) => {
    chart.data = data;
    
    const dateAxis = chart.xAxes.push(new am4charts.DateAxis());
    dateAxis.renderer.grid.template.location = 0;
    
    const valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
    valueAxis.tooltip.disabled = true;
    valueAxis.renderer.minWidth = 35;
    
    const series = chart.series.push(new am4charts.LineSeries());
    series.dataFields.dateX = "date";
    series.dataFields.valueY = "value";
    series.tooltipText = "{valueY.value}";
  });

  return <div ref={amchartsElRef} />;
};
```

### Example

To run Storybook example:
- `git clone`
- `npm install`
- `npm run storybook`

---
_Source: https://npm.io/package/use-amcharts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
