jmchart 1.2.20 → 1.2.21

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
@@ -703,6 +703,85 @@ chart.on('marklinemove', (args) => {
703
703
  8. **数组副作用防护**:`Array.reverse()` 使用 `slice()` 先拷贝再反转,避免修改原数组
704
704
  9. **浅拷贝优化**:对于不需要深拷贝的场景使用 `Object.assign` 替代深拷贝
705
705
 
706
+ ## 最佳实践
707
+
708
+ ### 1. 大数据量优化
709
+ 当数据量较大时(>100条),建议:
710
+ - 禁用动画:`enableAnimate: false`
711
+ - 减少数据点显示:`showItem: false`
712
+ - 使用 `touchGraph: true` 提升交互性能
713
+
714
+ ### 2. 响应式设计
715
+ ```javascript
716
+ const chart = new jmChart(container, {
717
+ width: container.clientWidth,
718
+ height: container.clientHeight
719
+ });
720
+
721
+ // 监听窗口大小变化
722
+ window.addEventListener('resize', () => {
723
+ chart.width = container.clientWidth;
724
+ chart.height = container.clientHeight;
725
+ chart.refresh();
726
+ });
727
+ ```
728
+
729
+ ### 3. 动态数据更新
730
+ ```javascript
731
+ // 更新数据后自动刷新
732
+ chart.data = newData;
733
+ chart.refresh();
734
+
735
+ // 或者使用自动刷新模式
736
+ const chart = new jmChart(container, {
737
+ autoRefresh: true
738
+ });
739
+ ```
740
+
741
+ ### 4. 自定义颜色
742
+ ```javascript
743
+ // 使用自定义颜色数组
744
+ const chart = new jmChart(container, {
745
+ style: {
746
+ chartColors: ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7']
747
+ }
748
+ });
749
+
750
+ // 或者使用颜色函数
751
+ chart.createSeries('line', {
752
+ field: 'value',
753
+ style: {
754
+ color: function(point) {
755
+ return point.yValue > 100 ? '#FF0000' : '#00FF00';
756
+ }
757
+ }
758
+ });
759
+ ```
760
+
761
+ ## 故障排除
762
+
763
+ ### 常见问题
764
+
765
+ 1. **图表不显示**
766
+ - 检查容器元素是否存在且有宽高
767
+ - 确认数据格式正确
768
+ - 检查浏览器控制台是否有错误
769
+
770
+ 2. **动画卡顿**
771
+ - 减少数据量或禁用动画
772
+ - 使用 `touchGraph: true` 优化交互性能
773
+ - 检查是否有内存泄漏
774
+
775
+ 3. **触摸事件不响应**
776
+ - 确认容器元素有正确的 CSS 定位
777
+ - 检查是否有其他元素遮挡
778
+ - 尝试启用 `touchGraph: true`
779
+
780
+ 4. **图表尺寸异常**
781
+ - 确保容器有明确的宽度和高度
782
+ - 检查 CSS 是否影响容器尺寸
783
+ - 使用 `chart.width` 和 `chart.height` 手动设置
784
+
706
785
  ## 开发
707
786
 
708
787
  ### 构建项目
@@ -772,4 +851,4 @@ MIT
772
851
  - 完善文档
773
852
 
774
853
  [npm-badge]: https://img.shields.io/npm/v/jmchart.svg
775
- [npm-badge-url]: https://www.npmjs.com/package/jmchart
854
+ [npm-badge-url]: https://www.npmjs.com/package/jmchart
@@ -14853,6 +14853,7 @@ define(['exports'], (function (exports) { 'use strict';
14853
14853
  const len = points.length;
14854
14854
  if (!len) return;
14855
14855
  this.style.stroke = this.style.color;
14856
+ this.style.fill = null;
14856
14857
  this.style.item.stroke = this.style.color;
14857
14858
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
14858
14859
  let shapePoints = [];
@@ -14994,8 +14995,8 @@ define(['exports'], (function (exports) { 'use strict';
14994
14995
  // 有指定绘制区域效果才展示
14995
14996
  if (!this.style.area || points.length < 2) return;
14996
14997
 
14997
- // 基线:取X轴的实际Y位置(chartArea相对坐标),没有X轴时用下边界
14998
- const axisY = this.graph.xAxis ? this.graph.xAxis.start.y - this.graph.chartArea.position.y : this.graph.chartArea.height;
14998
+ // 基线:使用数据基准线(baseY),在 createPoints 中已根据 minY/baseYValue 正确计算
14999
+ const axisY = this.baseY;
14999
15000
 
15000
15001
  // 过滤有效点
15001
15002
  const validPoints = points.filter(p => p.y != null && typeof p.y !== 'undefined');
@@ -15030,6 +15031,8 @@ define(['exports'], (function (exports) { 'use strict';
15030
15031
  const style = this.graph.utils.clone(this.style.area, {}, true);
15031
15032
  // 连框颜色如果没指定,就透明
15032
15033
  style.stroke = style.stroke || 'transparent';
15034
+ // 闭合路径,确保 fill/stroke 正确封闭多边形
15035
+ style.close = true;
15033
15036
  if (!style.fill) {
15034
15037
  const color = this.graph.utils.hexToRGBA(this.style.stroke);
15035
15038
  if (isAbove) {
@@ -14855,6 +14855,7 @@ class jmLineSeries extends jmSeries {
14855
14855
  const len = points.length;
14856
14856
  if (!len) return;
14857
14857
  this.style.stroke = this.style.color;
14858
+ this.style.fill = null;
14858
14859
  this.style.item.stroke = this.style.color;
14859
14860
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
14860
14861
  let shapePoints = [];
@@ -14996,8 +14997,8 @@ class jmLineSeries extends jmSeries {
14996
14997
  // 有指定绘制区域效果才展示
14997
14998
  if (!this.style.area || points.length < 2) return;
14998
14999
 
14999
- // 基线:取X轴的实际Y位置(chartArea相对坐标),没有X轴时用下边界
15000
- const axisY = this.graph.xAxis ? this.graph.xAxis.start.y - this.graph.chartArea.position.y : this.graph.chartArea.height;
15000
+ // 基线:使用数据基准线(baseY),在 createPoints 中已根据 minY/baseYValue 正确计算
15001
+ const axisY = this.baseY;
15001
15002
 
15002
15003
  // 过滤有效点
15003
15004
  const validPoints = points.filter(p => p.y != null && typeof p.y !== 'undefined');
@@ -15032,6 +15033,8 @@ class jmLineSeries extends jmSeries {
15032
15033
  const style = this.graph.utils.clone(this.style.area, {}, true);
15033
15034
  // 连框颜色如果没指定,就透明
15034
15035
  style.stroke = style.stroke || 'transparent';
15036
+ // 闭合路径,确保 fill/stroke 正确封闭多边形
15037
+ style.close = true;
15035
15038
  if (!style.fill) {
15036
15039
  const color = this.graph.utils.hexToRGBA(this.style.stroke);
15037
15040
  if (isAbove) {
@@ -14851,6 +14851,7 @@ class jmLineSeries extends jmSeries {
14851
14851
  const len = points.length;
14852
14852
  if (!len) return;
14853
14853
  this.style.stroke = this.style.color;
14854
+ this.style.fill = null;
14854
14855
  this.style.item.stroke = this.style.color;
14855
14856
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
14856
14857
  let shapePoints = [];
@@ -14992,8 +14993,8 @@ class jmLineSeries extends jmSeries {
14992
14993
  // 有指定绘制区域效果才展示
14993
14994
  if (!this.style.area || points.length < 2) return;
14994
14995
 
14995
- // 基线:取X轴的实际Y位置(chartArea相对坐标),没有X轴时用下边界
14996
- const axisY = this.graph.xAxis ? this.graph.xAxis.start.y - this.graph.chartArea.position.y : this.graph.chartArea.height;
14996
+ // 基线:使用数据基准线(baseY),在 createPoints 中已根据 minY/baseYValue 正确计算
14997
+ const axisY = this.baseY;
14997
14998
 
14998
14999
  // 过滤有效点
14999
15000
  const validPoints = points.filter(p => p.y != null && typeof p.y !== 'undefined');
@@ -15028,6 +15029,8 @@ class jmLineSeries extends jmSeries {
15028
15029
  const style = this.graph.utils.clone(this.style.area, {}, true);
15029
15030
  // 连框颜色如果没指定,就透明
15030
15031
  style.stroke = style.stroke || 'transparent';
15032
+ // 闭合路径,确保 fill/stroke 正确封闭多边形
15033
+ style.close = true;
15031
15034
  if (!style.fill) {
15032
15035
  const color = this.graph.utils.hexToRGBA(this.style.stroke);
15033
15036
  if (isAbove) {
@@ -14854,6 +14854,7 @@ var jmChart = (function (exports) {
14854
14854
  const len = points.length;
14855
14855
  if (!len) return;
14856
14856
  this.style.stroke = this.style.color;
14857
+ this.style.fill = null;
14857
14858
  this.style.item.stroke = this.style.color;
14858
14859
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
14859
14860
  let shapePoints = [];
@@ -14995,8 +14996,8 @@ var jmChart = (function (exports) {
14995
14996
  // 有指定绘制区域效果才展示
14996
14997
  if (!this.style.area || points.length < 2) return;
14997
14998
 
14998
- // 基线:取X轴的实际Y位置(chartArea相对坐标),没有X轴时用下边界
14999
- const axisY = this.graph.xAxis ? this.graph.xAxis.start.y - this.graph.chartArea.position.y : this.graph.chartArea.height;
14999
+ // 基线:使用数据基准线(baseY),在 createPoints 中已根据 minY/baseYValue 正确计算
15000
+ const axisY = this.baseY;
15000
15001
 
15001
15002
  // 过滤有效点
15002
15003
  const validPoints = points.filter(p => p.y != null && typeof p.y !== 'undefined');
@@ -15031,6 +15032,8 @@ var jmChart = (function (exports) {
15031
15032
  const style = this.graph.utils.clone(this.style.area, {}, true);
15032
15033
  // 连框颜色如果没指定,就透明
15033
15034
  style.stroke = style.stroke || 'transparent';
15035
+ // 闭合路径,确保 fill/stroke 正确封闭多边形
15036
+ style.close = true;
15034
15037
  if (!style.fill) {
15035
15038
  const color = this.graph.utils.hexToRGBA(this.style.stroke);
15036
15039
  if (isAbove) {
@@ -14856,6 +14856,7 @@ System.register([], (function (exports) {
14856
14856
  const len = points.length;
14857
14857
  if (!len) return;
14858
14858
  this.style.stroke = this.style.color;
14859
+ this.style.fill = null;
14859
14860
  this.style.item.stroke = this.style.color;
14860
14861
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
14861
14862
  let shapePoints = [];
@@ -14997,8 +14998,8 @@ System.register([], (function (exports) {
14997
14998
  // 有指定绘制区域效果才展示
14998
14999
  if (!this.style.area || points.length < 2) return;
14999
15000
 
15000
- // 基线:取X轴的实际Y位置(chartArea相对坐标),没有X轴时用下边界
15001
- const axisY = this.graph.xAxis ? this.graph.xAxis.start.y - this.graph.chartArea.position.y : this.graph.chartArea.height;
15001
+ // 基线:使用数据基准线(baseY),在 createPoints 中已根据 minY/baseYValue 正确计算
15002
+ const axisY = this.baseY;
15002
15003
 
15003
15004
  // 过滤有效点
15004
15005
  const validPoints = points.filter(p => p.y != null && typeof p.y !== 'undefined');
@@ -15033,6 +15034,8 @@ System.register([], (function (exports) {
15033
15034
  const style = this.graph.utils.clone(this.style.area, {}, true);
15034
15035
  // 连框颜色如果没指定,就透明
15035
15036
  style.stroke = style.stroke || 'transparent';
15037
+ // 闭合路径,确保 fill/stroke 正确封闭多边形
15038
+ style.close = true;
15036
15039
  if (!style.fill) {
15037
15040
  const color = this.graph.utils.hexToRGBA(this.style.stroke);
15038
15041
  if (isAbove) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmchart",
3
- "version": "1.2.20",
3
+ "version": "1.2.21",
4
4
  "description": "chart",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
package/server.js CHANGED
@@ -53,6 +53,9 @@ function startServer() {
53
53
  if (!serverInstance) {
54
54
  const app = express();
55
55
  app.use(express.static("."));
56
+ app.get("*", (req, res) => {
57
+ res.sendFile("example/index.html", { root: __dirname });
58
+ });
56
59
  serverInstance = app.listen(port, ip, () => {
57
60
  console.log(`\n🔥 开发服务器启动成功!`);
58
61
  console.log(`🌐 访问地址: http://${ip}:${port}`);
@@ -33,6 +33,7 @@ export default class jmLineSeries extends jmSeries {
33
33
  if(!len) return;
34
34
 
35
35
  this.style.stroke = this.style.color;
36
+ this.style.fill = null;
36
37
  this.style.item.stroke = this.style.color;
37
38
 
38
39
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
@@ -193,10 +194,8 @@ export default class jmLineSeries extends jmSeries {
193
194
  // 有指定绘制区域效果才展示
194
195
  if(!this.style.area || points.length < 2) return;
195
196
 
196
- // 基线:取X轴的实际Y位置(chartArea相对坐标),没有X轴时用下边界
197
- const axisY = this.graph.xAxis
198
- ? this.graph.xAxis.start.y - this.graph.chartArea.position.y
199
- : this.graph.chartArea.height;
197
+ // 基线:使用数据基准线(baseY),在 createPoints 中已根据 minY/baseYValue 正确计算
198
+ const axisY = this.baseY;
200
199
 
201
200
  // 过滤有效点
202
201
  const validPoints = points.filter(p => p.y != null && typeof p.y !== 'undefined');
@@ -233,6 +232,8 @@ export default class jmLineSeries extends jmSeries {
233
232
  const style = this.graph.utils.clone(this.style.area, {}, true);
234
233
  // 连框颜色如果没指定,就透明
235
234
  style.stroke = style.stroke || 'transparent';
235
+ // 闭合路径,确保 fill/stroke 正确封闭多边形
236
+ style.close = true;
236
237
 
237
238
  if(!style.fill) {
238
239
  const color = this.graph.utils.hexToRGBA(this.style.stroke);