# omi-chart

> Simple HTML5 Charts using the tag powered by [omi](https://github.com/Tencent/omi) and [chart.js](https://www.chartjs.org/).

Latest version **1.0.1** (published 2018-12-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install omi-chart
pnpm add omi-chart
yarn add omi-chart
bun add omi-chart
```

## Health

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

Positive: esm support; no vulnerabilities; popular repo.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-12-13 |
| First published | 2018-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 30.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13265 |
| Author | dntzhang |
| Maintainers | dntzhang |
| Keywords | chart.js, omi, omi-chart |

## Links

- npm: https://www.npmjs.com/package/omi-chart
- Repository: https://github.com/Tencent/omi
- Homepage: https://github.com/Tencent/omi/tree/master/packages/omi-chart
- Issues: https://github.com/Tencent/omi/issues
- npm.io page: https://npm.io/package/omi-chart

## Dependencies (2)

- [omi](https://npm.io/package/omi.md) latest
- [chart.js](https://npm.io/package/chart.js.md) latest

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-12-13
- 1.0.0 — 2018-12-12
- 0.0.0 — 2018-12-10

## README

<p align="right">v<strong>1.0.1</strong></p>
<p align="center"><img src="./assets/omi-chart.svg" alt="omi-chart" width="300"/></p>
<h2 align="center">omi-chart</h2>
<p  align="center">Simple HTML5 Charts using <strong>chart-x</strong> tag powered by <a href="https://github.com/Tencent/omi">omi</a> and <a href="https://www.chartjs.org/" rel="nofollow">chart.js</a>.</p>

---

[![omi-chart](./assets/omi-chart2.png)](https://tencent.github.io/omi/packages/omi-chart/repl/index.html)

- Bar charts
  - [Simple](https://tencent.github.io/omi/packages/omi-chart/repl/index.html)
  - [Vertical](https://tencent.github.io/omi/packages/omi-chart/repl/bar-vertical.html)
  - [Horizontal](https://tencent.github.io/omi/packages/omi-chart/repl/bar-horizontal.html)
  - [Multi Axis](https://tencent.github.io/omi/packages/omi-chart/repl/bar-multi-axis.html)
  - [Stacked Group](https://tencent.github.io/omi/packages/omi-chart/repl/bar-stacked-group.html)
- Line charts
  - [Base](https://tencent.github.io/omi/packages/omi-chart/repl/line-base.html)
  - [Multi Axis](https://tencent.github.io/omi/packages/omi-chart/repl/line-multi-axis.html)
  - [Stepped](https://tencent.github.io/omi/packages/omi-chart/repl/line-stepped.html)
  - [Fill](https://tencent.github.io/omi/packages/omi-chart/repl/line-fill.html)
  - [Interpolation Modes](https://tencent.github.io/omi/packages/omi-chart/repl/line-interpolation-modes.html)
  - [Point Sizes](https://tencent.github.io/omi/packages/omi-chart/repl/line-point-sizes.html)
  - [Styles](https://tencent.github.io/omi/packages/omi-chart/repl/line-styles.html)    
  - [Point Styles](https://tencent.github.io/omi/packages/omi-chart/repl/line-point-styles.html)    
- Scatter charts
  - [Base](https://tencent.github.io/omi/packages/omi-chart/repl/scatter-base.html)
  - [Multi Axis](https://tencent.github.io/omi/packages/omi-chart/repl/radar-multi-axis.html)
- Other charts
  - [Pie](https://tencent.github.io/omi/packages/omi-chart/repl/pie.html)
  - [Doughnut](https://tencent.github.io/omi/packages/omi-chart/repl/doughnut.html)
  - [Radar](https://tencent.github.io/omi/packages/omi-chart/repl/radar.html)
  - [PolarArea](https://tencent.github.io/omi/packages/omi-chart/repl/polar-area.html)
  - [Bubble](https://tencent.github.io/omi/packages/omi-chart/repl/bubble.html)
  - [Bar Line](https://tencent.github.io/omi/packages/omi-chart/repl/bar-line.html)

## Usage

```js
define('my-app', class extends WeElement {
  install(){
    this.chartData = {
      labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
      datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: '#f391a9',
        borderColor: '#ef5b9c',
        borderWidth: 1
      }]
    }
    
    this.chartOptions = {
      scales: {
        yAxes: [{
          ticks: {
            beginAtZero: true
          }
        }]
      }
    }
  }

  render(props, data) {
    return (
      <div>
        <chart-bar width={600} data={this.chartData} options={this.chartOptions} />
      </div>
    )
  }
})

render(<my-app />, 'body')
```

## Supports type

* `<chart-bar />`
* `<chart-line />`
* `<chart-scatter />`
* `<chart-pie />`
* `<chart-doughnut />`
* `<chart-radar />`
* `<chart-polar-area />`
* `<chart-bubble />`

## Principle

```js
import { WeElement, define } from 'omi'
import Chart from 'chart.js'

class ChartBase extends WeElement {
  receiveProps(props) {
    this.chart.data = props.data
    this.chart.options = props.options
    this.chart.update()
  }

  render(props) {
    return (
      <div style={{ width: props.width + 'px', height: props.height + 'px' }}>
        <canvas ref={(e) => { this.canvas = e }}>
        </canvas>
      </div>
    )
  }
}

define('chart-bar', class extends ChartBase {
  installed() {
    this.chart = new Chart(this.canvas.getContext('2d'), {
      type: this.props.horizontal ? 'horizontalBar' : 'bar',
      data: this.props.data,
      options: this.props.options
    })
  }
})


define('chart-line', class extends ChartBase {
  installed() {
    this.chart = new Chart(this.canvas.getContext('2d'), {
      type: 'line',
      data: this.props.data,
      options: this.props.options
    })
  }
})


define('chart-scatter', class extends ChartBase {
  installed() {
    this.chart = new Chart.Scatter(this.canvas.getContext('2d'), {
      data: this.props.data,
      options: this.props.options
    })
  }
})
```

## License

MIT

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