npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-webview-highcharts

v1.0.1

Published

a chart library based on Highcharts for React Native

Downloads

6

Readme

React Native Webview Highcharts

React Native Webview Highcharts is a chart library based on Highcharts for React Native.

Note:

React Native Webview Highcharts needs to be used with react-native-webview.

Install

use npm:

npm install react-native-webview-highcharts

If you haven't installed react-native-webview yet, please install it.

Usage

import React, { Component, useRef } from 'react';
import {Platform} from 'react-native';
import { WebView, WebViewMessageEvent } from 'react-native-webview';
import { create, update } from 'react-native-webview-highcharts';

function Demo() {
  const chartRef = useRef<WebView>(null);

  const onMessage = ({nativeEvent}: WebViewMessageEvent) => {
    const {event} = JSON.parse(nativeEvent.data);
    if (event === 'created') {
      doSomething();
    }
  };

  const onLoad = () => {
    const js = create(configOptions); // init the chart
    chartRef.current?.injectJavaScript(js);
  };

  const doSomething = () => {
    /*
     * do something
     * ....
     */

    const js = update(configOptions); // update the chart
    chartRef.current?.injectJavaScript(js);
  }

  let source
  if (Platform.OS === 'ios') {
    source = require("react-native-webview-highcharts/dist/index.html")
  } else {
    const prefix = 'file:///android_asset/raw/';
    const path = 'node_modules_reactnativewebviewhighcharts_dist_index.html';
    source = {uri: `${prefix}${path}`}
  }
  render() {
    return (
      <WebView
        ref={chartRef}
        source={source}
        originWhitelist={['*']}
        onMessage={onMessage}
        onLoad={onLoad}
        scrollEnabled={false}
      />
    );
  }
}

API

There are two methods in React Native Webview Highcharts:

1. create(configOptions)

The create method creates a chart by calling the initialization function Highcharts.chart. When the chart is created, window.ReactNativeWebView.postMessage(data) is called so that React Native can know that the chart has been created. Among them, the parameter data of postMessage is JSON.stringify({event:'created'}).

2. update(configOptions)

When you want to update the chart, you need to use the update method at this time.

The update method will call Highcharts' update method to update the chart, and then call window.ReactNativeWebView.postMessage(data) to send a message to tell React Native that the chart is updated. Among them, the parameter data of postMessage is JSON.stringify({event:'updated'}).

configOptions

configOptions is the parameter of create and update methods, it inherits the chart configuration of Highcharts, and it can also have the following three attributes:

name | type | required | description -- | -- | -- | -- | xAxisPrecision | number | no | x-axis label formatting precision yAxisPrecision | number | no | y-axis label formatting precision debug | boolean | no | debug mode

When the X-axis or Y-axis label is a number, we often need to format the number according to the precision. At this time, we can configure xAxisPrecision or yAxisPrecision. Of course, we can also customize the formatting function in the configuration, that is, configure the xAxis.labels.formatter method.