0.1.1 • Published 4 years ago

react-native-highcharts-wrapper v0.1.1

Weekly downloads
7
License
MIT
Repository
-
Last release
4 years ago

react-native-highcharts-wrapper

Easy to use wrapper to utilise Highcharts within react-native applications.

Getting Started

npm install react-native-highcharts-wrapper

or

yarn add react-native-highcharts-wrapper

Example

import ChartView from 'react-native-highcharts-wrapper';

export default function HighChart() {
  const Highcharts = 'Highcharts';
  const conf = {
    chart: {
      type: 'spline',
      animation: Highcharts.svg,
      marginRight: 10,
      events: {
        load: function () {
          const series = this.series[0];
          setInterval(function () {
            const x = new Date().getTime(),
              y = Math.random() * (13000 - 12000) + 12000;
            series.addPoint([x, y], true, true);
          }, 2000);
        },
      },
    },
    title: {
      text: 'Live Bitcoin Price',
    },
    xAxis: { type: 'datetime', tickPixelInterval: 150 },
    yAxis: {
      title: { text: 'Price USD' },
      plotLines: [{ value: 0, width: 1, color: '#CCC' }],
    },
    tooltip: {
      formatter: function () {
        return (
          '<b>' +
          this.series.name +
          '</b><br/>' +
          Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +
          '<br/>' +
          Highcharts.numberFormat(this.y, 2)
        );
      },
    },
    exporting: { enabled: false },
    series: [
      {
        name: 'BTC',
        data: (function () {
          // generate an array of random data
          const data = [];
          const time = new Date().getTime();
          for (let i = -19; i <= 0; i += 1) {
            data.push({
              x: time + i * 2000,
              y: Math.random() * (13000 - 12000) + 12000,
            });
          }
          return data;
        })(),
      },
    ],
  };

  const options = {
    global: { useUTC: false },
    lang: { decimalPoint: ',', thousandsSep: '.' },
  };

  return <ChartView style={{ height: 350 }} config={conf} options={options} />;
}

Props

PropRequiredDescription
configtrueHighcharts configuration See the docs.>>
stockfalseUse Highstock instead of Highcharts - Default false
stylefalseStyle object to be passed into the WebView
heatMapfalseUse HeatMap - Default false
optionsfalsePass global and lang options into Highcharts
enableRadiusPiefalseImport radius pie library from highcharts - Default false
morefalseImport highstock-more library - Default false
guagefalseImport gauge library from highcharts - Default false