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

v1.1.0

Published

F2 charts for react-native

Downloads

192

Readme

react-native-f2chart

F2 charts for react-native

install

1、

yarn add react-native-f2chart or npm i react-native-f2chart

2、 copy node_moules/react-native-f2chart/src/f2chart.html to android/app/src/main/assets/f2chart.html

simple demo example

usage

import Chart from "react-native-f2chart";

// 参考 https://antv.alipay.com/zh-cn/f2/3.x/demo/line/basic.html
const initScript = data =>`
(function(){
    chart =  new F2.Chart({
        id: 'chart',
        pixelRatio: window.devicePixelRatio,
    });
    chart.source(${JSON.stringify(data)}, {
    value: {
    tickCount: 5,
    min: 0
    },
    date: {
    type: 'timeCat',
    range: [0, 1],
    tickCount: 3
    }
    });
    chart.tooltip({
    custom: true,
    showXTip: true,
    showYTip: true,
    snap: true,
    onChange: function(obj) {
        window.postMessage(stringify(obj))
    },
    crosshairsType: 'xy',
    crosshairsStyle: {
    lineDash: [2]
    }
    });
    chart.axis('date', {
    label: function label(text, index, total) {
    var textCfg = {};
    if (index === 0) {
        textCfg.textAlign = 'left';
    } else if (index === total - 1) {
        textCfg.textAlign = 'right';
    }
    return textCfg;
    }
    });
    chart.line().position('date*value');
    chart.render();
})();
`;

    ...
    render() {
        return (
            <View style={{ height: 350 }}>
              <Chart initScript={initScript(data)} />
            </View>
        )
    }
    ...
`

Props

| Prop | type | Description | Required | | ------------ | ------------- | ------------------------------------------------------------------------------------------- | -------- | | initScript | string | 初始化图表的 js 代码,参考 f2 的文档 | yes | | data | Array | f2 chart source | no | | onChange | Function | tooltip onchange | no | | webView | ReactElement | 渲染图表的 webview,可以使用 react-native-webview 代替,默认使用 react-natve 里面的 webview | no |

Notice

  • chart 已经在源码的 html 定义过了,在 initScript 中,并不需要定义 chart,直接给 chart 赋值即可
  • tooltip onchange 中 传输数据时用到的 stringify 也是在 html 定义好的,可以直接使用,用 JSON.stringify 会报错, 原因
  • 如果使用的是 react-native-webview,在 tooltip 中的 postMessage 应该为 window.ReactNativeWebView.postMessage