|
| 1 | +[](https://wuba.github.io/react-native-echarts/) |
| 2 | += |
| 3 | + |
| 4 | +[](https://www.npmjs.com/package/@wuba/react-native-echarts) |
| 5 | +[](https://www.npmjs.com/package/@wuba/react-native-echarts) |
| 6 | +[](https://codecov.io/gh/wuba/react-native-echarts) |
| 7 | +[](https://github.com/wuba/react-native-echarts/issues) |
| 8 | +[](https://github.com/wuba/react-native-echarts/graphs/contributors) |
| 9 | +[](https://github.com/wuba/react-native-echarts/pulls) |
| 10 | +[](https://github.com/wuba/react-native-echarts/blob/main/LICENSE) |
| 11 | + |
| 12 | +[简体中文](./README_CN.md) | [English](./README.md) | [日本語](./README_JP.md) | [繁體中文](./README_TW.md) |
| 13 | + |
| 14 | +[React Native](https://reactnative.dev/) 版本的 [Apache Echarts](https://github.com/apache/echarts),基於 [react-native-svg](https://github.com/software-mansion/react-native-svg) 和 [react-native-skia](https://github.com/shopify/react-native-skia)。相比基於 WebView 的解決方案提供了顯著的性能提升。 |
| 15 | + |
| 16 | +可在[官網查看完整的文檔](https://wuba.github.io/react-native-echarts/zh-hant/)。 |
| 17 | + |
| 18 | +## 關於 |
| 19 | + |
| 20 | +* 🔥 與 Apache ECharts 的使用方式相同 |
| 21 | +* 🎨 豐富的圖表支持,涵蓋幾乎所有的使用場景 |
| 22 | +* ✨ 可選的渲染庫:[Skia](https://github.com/shopify/react-native-skia) 或 [SVG](https://github.com/software-mansion/react-native-svg) |
| 23 | +* 🚀 可與 Web 復用的代碼 |
| 24 | +* 📱 支持點擊、拖拽、縮放等手勢 |
| 25 | + |
| 26 | +## 安裝 |
| 27 | + |
| 28 | +```sh |
| 29 | +yarn add @wuba/react-native-echarts echarts |
| 30 | +``` |
| 31 | + |
| 32 | +根據您的需要安裝 [react-native-svg](https://github.com/software-mansion/react-native-svg#installation) 或 [react-native-skia](https://shopify.github.io/react-native-skia/docs/getting-started/installation/)。 |
| 33 | + |
| 34 | +> 推薦使用最新版本的 echarts、react-native-svg 和 react-native-skia |
| 35 | +
|
| 36 | +## 用法 |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +大多數 ECharts 中的圖表都受支持,使用方法基本保持一致。關於更多使用案例和演示預覽,您可以下載 [Taro Playground](https://github.com/wuba/taro-playground) 應用程序。 |
| 41 | + |
| 42 | +### 示例 |
| 43 | +```js |
| 44 | +// 選擇您喜歡的渲染器 |
| 45 | +// import { SkiaChart, SVGRenderer } from '@wuba/react-native-echarts'; |
| 46 | +import { SvgChart, SVGRenderer } from '@wuba/react-native-echarts'; |
| 47 | +import * as echarts from 'echarts/core'; |
| 48 | +import { useRef, useEffect } from 'react'; |
| 49 | +import { |
| 50 | + BarChart, |
| 51 | +} from 'echarts/charts'; |
| 52 | +import { |
| 53 | + TitleComponent, |
| 54 | + TooltipComponent, |
| 55 | + GridComponent, |
| 56 | +} from 'echarts/components'; |
| 57 | + |
| 58 | +// 註冊擴展組件 |
| 59 | +echarts.use([ |
| 60 | + TitleComponent, |
| 61 | + TooltipComponent, |
| 62 | + GridComponent, |
| 63 | + SVGRenderer, |
| 64 | + // ... |
| 65 | + BarChart, |
| 66 | +]) |
| 67 | + |
| 68 | +const E_HEIGHT = 250; |
| 69 | +const E_WIDTH = 300; |
| 70 | + |
| 71 | +// 初始化 |
| 72 | +function ChartComponent({ option }) { |
| 73 | + const chartRef = useRef<any>(null); |
| 74 | + |
| 75 | + useEffect(() => { |
| 76 | + let chart: any; |
| 77 | + if (chartRef.current) { |
| 78 | + // @ts-ignore |
| 79 | + chart = echarts.init(chartRef.current, 'light', { |
| 80 | + renderer: 'svg', |
| 81 | + width: E_WIDTH, |
| 82 | + height: E_HEIGHT, |
| 83 | + }); |
| 84 | + chart.setOption(option); |
| 85 | + } |
| 86 | + return () => chart?.dispose(); |
| 87 | + }, [option]); |
| 88 | + |
| 89 | + // 選擇你偏愛的圖表組件 |
| 90 | + // return <SkiaChart ref={chartRef} />; |
| 91 | + return <SvgChart ref={chartRef} />; |
| 92 | +} |
| 93 | + |
| 94 | +// 組件使用 |
| 95 | +export default function App() { |
| 96 | + const option = { |
| 97 | + xAxis: { |
| 98 | + type: 'category', |
| 99 | + data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], |
| 100 | + }, |
| 101 | + yAxis: { |
| 102 | + type: 'value', |
| 103 | + }, |
| 104 | + series: [ |
| 105 | + { |
| 106 | + data: [120, 200, 150, 80, 70, 110, 130], |
| 107 | + type: 'bar', |
| 108 | + }, |
| 109 | + ], |
| 110 | + } |
| 111 | + return <ChartComponent option={option} /> |
| 112 | +} |
| 113 | +``` |
| 114 | +
|
| 115 | +### 只使用 SvgChart 或 SkiaChart 中的一個 |
| 116 | +```js |
| 117 | +import SvgChart, { SVGRenderer } from '@wuba/react-native-echarts/svgChart'; |
| 118 | +``` |
| 119 | +或 |
| 120 | +```js |
| 121 | +import SkiaChart, { SkiaRenderer } from '@wuba/react-native-echarts/skiaChart'; |
| 122 | +``` |
| 123 | +
|
| 124 | +## 貢獻 |
| 125 | +
|
| 126 | +請參閱 [貢獻指南](CONTRIBUTING.md) 以了解如何為倉庫做出貢獻以及開發工作流程。 |
| 127 | +
|
| 128 | +## 貢獻者 |
| 129 | +
|
| 130 | +這個項目的存在要感謝所有做出貢獻的人: |
| 131 | +
|
| 132 | +[](https://github.com/wuba/react-native-echarts/graphs/contributors) |
| 133 | +
|
| 134 | +## 許可 |
| 135 | +
|
| 136 | +Apache-2.0 |
| 137 | +
|
| 138 | +--- |
| 139 | +
|
| 140 | +使用 [create-react-native-library](https://github.com/callstack/react-native-builder-bob) 創建。 |
0 commit comments