jmchart 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,41 +1,323 @@
1
- jmchart
2
- =========
3
-
4
- [![Latest NPM release][npm-badge]][npm-badge-url]
5
- [![Build Status](https://travis-ci.org/jiamao/jmchart.svg?branch=master)](https://travis-ci.org/jiamao/jmchart)
6
-
7
- jmchart 轻量级图表组件(支持微信小程序),依赖 [jmgraph](https://github.com/jiamao/jmgraph)
8
- =======
9
-
10
- html5图表控件
11
-
12
- 线条[http://jiamao.github.io/jmchart/example/line.html]
13
-
14
- 柱图[http://jiamao.github.io/jmchart/example/bar.html]
15
-
16
- 饼图[http://jiamao.github.io/jmchart/example/pie.html]
17
-
18
- 雷达图[http://jiamao.github.io/jmchart/example/radar.html]
19
-
20
- K线[http://jiamao.github.io/jmchart/example/candlestick.html]
21
-
22
- stackBar[http://jiamao.github.io/jmchart/example/stackBar.html]
23
-
24
- stackLine[http://jiamao.github.io/jmchart/example/stackLine.html]
25
-
26
- vue[http://jiamao.github.io/jmchart/example/vue.html]
27
-
28
- 微信小程序[https://github.com/jiamao/mini-jmchart]
29
-
30
-
31
- 安装
32
- ---
33
- 如需要构建,直接在项目录下执行`npm run build`即可。
34
- ```shell
35
- npm install jmchart
36
- ```
37
-
38
- > 如果你想引用不同的类型的模块,请见`dist`目录。1
39
- >
40
- [npm-badge]: https://img.shields.io/npm/v/jmchart.svg
1
+ # jmchart
2
+
3
+ [![Latest NPM release][npm-badge]][npm-badge-url]
4
+ [![Build Status](https://travis-ci.org/fefeding/jmchart.svg?branch=master)](https://travis-ci.org/fefeding/jmchart)
5
+
6
+ ## 简介
7
+
8
+ jmchart 是一个轻量级、高性能的图表组件,支持微信小程序,基于 [jmgraph](https://github.com/fefeding/jmgraph) 构建。它提供了丰富的图表类型和灵活的配置选项,适用于各种数据可视化场景。
9
+
10
+ ## 特性
11
+
12
+ - **轻量级**:代码体积小,加载速度快
13
+ - **高性能**:优化的渲染引擎,支持大数据量
14
+ - **多图表类型**:支持折线图、柱状图、饼图、雷达图、K线图、堆叠图等
15
+ - **动画效果**:支持流畅的入场动画
16
+ - **响应式**:自适应容器大小
17
+ - **跨平台**:支持浏览器和微信小程序
18
+ - **高度可定制**:丰富的样式配置选项
19
+ - **事件支持**:完整的鼠标/触摸事件系统
20
+
21
+ ## 支持的图表类型
22
+
23
+ - **折线图** (line) - 展示数据趋势
24
+ - **柱状图** (bar) - 对比数据大小
25
+ - **饼图** (pie) - 展示数据占比
26
+ - **雷达图** (radar) - 多维度数据对比
27
+ - **K线图** (candlestick) - 金融数据展示
28
+ - **堆叠柱状图** (stackBar) - 多系列数据堆叠
29
+ - **堆叠折线图** (stackLine) - 多系列数据堆叠
30
+
31
+ ## 在线示例
32
+
33
+ - [折线图](http://fefeding.github.io/jmchart/example/line.html)
34
+ - [柱状图](http://fefeding.github.io/jmchart/example/bar.html)
35
+ - [饼图](http://fefeding.github.io/jmchart/example/pie.html)
36
+ - [雷达图](http://fefeding.github.io/jmchart/example/radar.html)
37
+ - [K线图](http://fefeding.github.io/jmchart/example/candlestick.html)
38
+ - [堆叠柱状图](http://fefeding.github.io/jmchart/example/stackBar.html)
39
+ - [堆叠折线图](http://fefeding.github.io/jmchart/example/stackLine.html)
40
+ - [Vue 示例](http://fefeding.github.io/jmchart/example/vue.html)
41
+ - [微信小程序](https://github.com/fefeding/mini-jmchart)
42
+
43
+ ## 安装
44
+
45
+ ```bash
46
+ npm install jmchart
47
+ ```
48
+
49
+ ## 快速开始
50
+
51
+ ### 基础用法
52
+
53
+ ```javascript
54
+ import jmChart from 'jmchart';
55
+
56
+ // 创建图表容器
57
+ const container = document.getElementById('chart-container');
58
+
59
+ // 初始化图表
60
+ const chart = new jmChart(container, {
61
+ width: 800,
62
+ height: 400,
63
+ enableAnimate: true
64
+ });
65
+
66
+ // 设置数据
67
+ chart.data = [
68
+ { name: '一月', value: 100 },
69
+ { name: '二月', value: 200 },
70
+ { name: '三月', value: 150 },
71
+ { name: '四月', value: 300 }
72
+ ];
73
+
74
+ // 创建折线图
75
+ const lineSeries = chart.createSeries('line', {
76
+ field: 'value',
77
+ xField: 'name'
78
+ });
79
+
80
+ // 刷新图表
81
+ chart.refresh();
82
+ ```
83
+
84
+ ### Vue 组件使用
85
+
86
+ ```vue
87
+ <template>
88
+ <v-chart
89
+ :chart-data="data"
90
+ :chart-series="series"
91
+ :chart-options="options"
92
+ @touch-point-change="handlePointChange"
93
+ />
94
+ </template>
95
+
96
+ <script>
97
+ import VChart from 'jmchart/component/vchart';
98
+
99
+ export default {
100
+ components: { VChart },
101
+ data() {
102
+ return {
103
+ data: [
104
+ { name: '一月', value: 100 },
105
+ { name: '二月', value: 200 },
106
+ { name: '三月', value: 150 }
107
+ ],
108
+ series: [{
109
+ type: 'line',
110
+ field: 'value'
111
+ }],
112
+ options: {
113
+ width: 600,
114
+ height: 400,
115
+ enableAnimate: true
116
+ }
117
+ }
118
+ },
119
+ methods: {
120
+ handlePointChange(args) {
121
+ console.log('数据点变化:', args);
122
+ }
123
+ }
124
+ }
125
+ </script>
126
+ ```
127
+
128
+ ## 配置选项
129
+
130
+ ### 图表配置
131
+
132
+ ```javascript
133
+ const options = {
134
+ // 图表尺寸
135
+ width: 800,
136
+ height: 400,
137
+
138
+ // 是否启用动画
139
+ enableAnimate: true,
140
+
141
+ // 是否自动刷新
142
+ autoRefresh: true,
143
+
144
+ // X轴字段名
145
+ xField: 'name',
146
+
147
+ // 图例位置: 'top' | 'bottom' | 'left' | 'right'
148
+ legendPosition: 'top',
149
+
150
+ // 是否显示图例
151
+ legendVisible: true,
152
+
153
+ // Y轴基线值
154
+ baseY: 0,
155
+
156
+ // X轴最小/最大值
157
+ minXValue: 0,
158
+ maxXValue: 100,
159
+
160
+ // Y轴最小/最大值
161
+ minYValue: 0,
162
+ maxYValue: 100,
163
+
164
+ // 样式配置
165
+ style: {
166
+ margin: { left: 40, top: 20, right: 20, bottom: 40 },
167
+ layout: 'normal'
168
+ }
169
+ };
170
+ ```
171
+
172
+ ### 图表类型配置
173
+
174
+ #### 折线图 (line)
175
+
176
+ ```javascript
177
+ chart.createSeries('line', {
178
+ field: 'value',
179
+ xField: 'name',
180
+ style: {
181
+ lineWidth: 2,
182
+ showItem: true, // 是否显示数据点
183
+ curve: true, // 是否平滑曲线
184
+ area: true, // 是否显示区域填充
185
+ radius: 4 // 数据点半径
186
+ }
187
+ });
188
+ ```
189
+
190
+ #### 柱状图 (bar)
191
+
192
+ ```javascript
193
+ chart.createSeries('bar', {
194
+ field: 'value',
195
+ xField: 'name',
196
+ style: {
197
+ perWidth: 0.5, // 柱子宽度占比
198
+ barWidth: 30 // 柱子固定宽度
199
+ }
200
+ });
201
+ ```
202
+
203
+ #### 饼图 (pie)
204
+
205
+ ```javascript
206
+ chart.createSeries('pie', {
207
+ field: 'value',
208
+ xField: 'name',
209
+ style: {
210
+ isHollow: false, // 是否空心圆
211
+ marginAngle: 0.1, // 扇形间隔角度
212
+ arcWidth: 0.2 // 空心圆环宽度
213
+ }
214
+ });
215
+ ```
216
+
217
+ #### 雷达图 (radar)
218
+
219
+ ```javascript
220
+ chart.createSeries('radar', {
221
+ field: ['value1', 'value2', 'value3'],
222
+ xField: 'name',
223
+ style: {
224
+ lineWidth: 2,
225
+ fill: 'rgba(0,0,0,0.2)'
226
+ }
227
+ });
228
+ ```
229
+
230
+ #### K线图 (candlestick)
231
+
232
+ ```javascript
233
+ chart.createSeries('candlestick', {
234
+ field: ['open', 'close', 'high', 'low'],
235
+ xField: 'date',
236
+ style: {
237
+ masculineColor: 'red', // 阳线颜色
238
+ negativeColor: 'green', // 阴线颜色
239
+ perWidth: 0.5
240
+ }
241
+ });
242
+ ```
243
+
244
+ ## API 文档
245
+
246
+ ### jmChart 类
247
+
248
+ #### 方法
249
+
250
+ - `createSeries(type, options)` - 创建图表序列
251
+ - `createXAxis(options)` - 创建X轴
252
+ - `createYAxis(options)` - 创建Y轴
253
+ - `reset()` - 重置图表
254
+ - `refresh()` - 刷新图表
255
+ - `destroy()` - 销毁图表
256
+ - `getColor(index)` - 获取颜色
257
+
258
+ #### 事件
259
+
260
+ - `touchPointChange` - 数据点变化事件
261
+ - `marklinelongtapstart` - 标线长按开始
262
+ - `marklinestartmove` - 标线开始移动
263
+ - `marklinemove` - 标线移动中
264
+ - `marklineendmove` - 标线移动结束
265
+
266
+ ## 性能优化
267
+
268
+ 本项目进行了以下性能优化:
269
+
270
+ 1. **动画阈值控制**:数据量超过100时自动禁用动画
271
+ 2. **缓存机制**:颜色计算等使用Map缓存
272
+ 3. **空值检查**:减少不必要的渲染和计算
273
+ 4. **代码优化**:移除冗余代码,优化循环和条件判断
274
+ 5. **常量提取**:提取魔法数字为命名常量
275
+ 6. **事件优化**:减少事件监听器的创建
276
+
277
+ ## 开发
278
+
279
+ ### 构建项目
280
+
281
+ ```bash
282
+ npm install
283
+ npm run build
284
+ ```
285
+
286
+ ### 运行开发服务器
287
+
288
+ ```bash
289
+ npm run dev
290
+ ```
291
+
292
+ ### 发布到NPM
293
+
294
+ ```bash
295
+ npm run push
296
+ ```
297
+
298
+ ## 浏览器支持
299
+
300
+ - Chrome (最新版)
301
+ - Firefox (最新版)
302
+ - Safari (最新版)
303
+ - Edge (最新版)
304
+ - 微信小程序
305
+
306
+ ## 许可证
307
+
308
+ MIT
309
+
310
+ ## 贡献
311
+
312
+ 欢迎提交 Issue 和 Pull Request!
313
+
314
+ ## 更新日志
315
+
316
+ ### v1.2.10
317
+ - 优化代码性能
318
+ - 添加缓存机制
319
+ - 改进动画控制
320
+ - 完善文档
321
+
322
+ [npm-badge]: https://img.shields.io/npm/v/jmchart.svg
41
323
  [npm-badge-url]: https://www.npmjs.com/package/jmchart
package/build.js CHANGED
@@ -1,36 +1,36 @@
1
-
2
- const rollup = require('rollup');
3
- const rollupOptions = require('./rollup.config.js');
4
-
5
- /**
6
- * format
7
- amd – 异步模块定义,用于像RequireJS这样的模块加载器
8
- cjs – CommonJS,适用于 Node 和 Browserify/Webpack
9
- esm – 将软件包保存为 ES 模块文件,在现代浏览器中可以通过 <script type=module> 标签引入
10
- iife – 一个自动执行的功能,适合作为<script>标签。(如果要为应用程序创建一个捆绑包,您可能想要使用它,因为它会使文件大小变小。)
11
- umd – 通用模块定义,以amd,cjs 和 iife 为一体
12
- system - SystemJS 加载器格式
13
- */
14
- async function build(format = 'cjs') {
15
- const bundle = await rollup.rollup(rollupOptions);
16
-
17
- const outputOptions = Object.assign(rollupOptions.output, {
18
- file: `./dist/jmchart.${format}.js`,
19
- format
20
- })
21
- const { code, map } = await bundle.generate(rollupOptions.output);
22
-
23
- await bundle.write(outputOptions);
24
- }
25
-
26
- build('cjs');
27
-
28
- build('esm');
29
-
30
- build('iife');
31
-
32
- build('amd');
33
-
34
- //build('umd');
35
-
1
+
2
+ const rollup = require('rollup');
3
+ const rollupOptions = require('./rollup.config.js');
4
+
5
+ /**
6
+ * format
7
+ amd – 异步模块定义,用于像RequireJS这样的模块加载器
8
+ cjs – CommonJS,适用于 Node 和 Browserify/Webpack
9
+ esm – 将软件包保存为 ES 模块文件,在现代浏览器中可以通过 <script type=module> 标签引入
10
+ iife – 一个自动执行的功能,适合作为<script>标签。(如果要为应用程序创建一个捆绑包,您可能想要使用它,因为它会使文件大小变小。)
11
+ umd – 通用模块定义,以amd,cjs 和 iife 为一体
12
+ system - SystemJS 加载器格式
13
+ */
14
+ async function build(format = 'cjs') {
15
+ const bundle = await rollup.rollup(rollupOptions);
16
+
17
+ const outputOptions = Object.assign(rollupOptions.output, {
18
+ file: `./dist/jmchart.${format}.js`,
19
+ format
20
+ })
21
+ const { code, map } = await bundle.generate(rollupOptions.output);
22
+
23
+ await bundle.write(outputOptions);
24
+ }
25
+
26
+ build('cjs');
27
+
28
+ build('esm');
29
+
30
+ build('iife');
31
+
32
+ build('amd');
33
+
34
+ //build('umd');
35
+
36
36
  build('system');