apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.54k stars 19.61k forks source link

[Feature] 折线图相邻数据值很大时会重合,能否优化下 #18488

Closed HOUSHENGREN closed 1 year ago

HOUSHENGREN commented 1 year ago

What problem does this feature solve?

折线图中,当数值很大时,相邻的数会重合

option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [150150150150150150150150150150150150150150150, 150150150150150150150150150150150150150150150, 224, 218, 135, 147, 260],
      type: 'line',
      label: {
        show: true,
        position: 'auto'
      }
    }
  ]
};

image

What does the proposed API look like?

希望像antV一样,可以自适应上下位置。

https://g2plot.antv.antgroup.com/zh/examples/line/basic/#line-point-style

import { Line } from '@antv/g2plot';

const data = [
  { year: '1991', value: 5555555555555555 },
  { year: '1992', value: 5555555555555555 },
  { year: '1993', value: 5555555555555555.5 },
  { year: '1994', value: 5555555555555555 },
  { year: '1995', value: 5555555555555555.9 },
  { year: '1996', value: 5555555555555555 },
  { year: '1997', value: 7 },
  { year: '1998', value: 9 },
  { year: '1999', value: 13 },
];

const line = new Line('container', {
  data,
  xField: 'year',
  yField: 'value',
  label: {},
  point: {
    size: 5,
    shape: 'diamond',
    style: {
      fill: 'white',
      stroke: '#5B8FF9',
      lineWidth: 2,
    },
  },
  tooltip: { showMarkers: false },
  state: {
    active: {
      style: {
        shadowBlur: 4,
        stroke: '#000',
        fill: 'red',
      },
    },
  },
  interactions: [{ type: 'marker-active' }],
});

line.render();

image

echarts-bot[bot] commented 1 year ago

@HOUSHENGREN It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗

TRANSLATED
**TITLE** [Feature] When the adjacent data values ​​of the line chart are large, they will overlap. Can it be optimized? **BODY** ### What problem does this feature solve? In the line chart, when the value is large, adjacent numbers will overlap ~~~ option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [ { data: [150150150150150150150150150150150150150150150, 150150150150150150150150150150150150150150150, 224, 218, 135, 147, 260], type: 'line', label: { show: true, position: 'auto' } } ] }; ~~~ ![image](https://user-images.githubusercontent.com/48871516/230821925-e863f8e3-8c23-4d58-aec7-02d48e3b3737.png) ### What does the proposed API look like? I hope that like antV, it can adapt to the upper and lower positions. https://g2plot.antv.antgroup.com/zh/examples/line/basic/#line-point-style ~~~ import { Line } from '@antv/g2plot'; const data = [ { year: '1991', value: 55555555555555555 }, { year: '1992', value: 55555555555555555 }, { year: '1993', value: 55555555555555555.5 }, { year: '1994', value: 55555555555555555 }, { year: '1995', value: 55555555555555555.9 }, { year: '1996', value: 55555555555555555 }, { year: '1997', value: 7 }, { year: '1998', value: 9 }, { year: '1999', value: 13 }, ]; const line = new Line('container', { data, xField: 'year', yField: 'value', label: {}, point: { size: 5, shape: 'diamond', style: { fill: 'white', stroke: '#5B8FF9', lineWidth: 2, }, }, tooltip: { showMarkers: false }, state: { active: { style: { shadowBlur: 4, stroke: '#000', fill: 'red', }, }, }, interactions: [{ type: 'marker-active' }], }); line. render(); ~~~ ![image](https://user-images.githubusercontent.com/48871516/230822510-cd9474fb-880d-42c7-8215-5ad18a8e42c8.png)
HOUSHENGREN commented 1 year ago

工厂按年的维度统计能耗,会出现数值巨大的情况

Ovilia commented 1 year ago

See the demo and checkout the doc.

HOUSHENGREN commented 1 year ago

See the demo and checkout the doc.

thank u very much!

HOUSHENGREN commented 1 year ago

See the demo and checkout the doc.

我想获取网格的宽度,或者网格一个单元格的宽度。通过判断文字宽度是否超过网格单元格的宽度,进而决定要不要对label数据进行位置的调整。没发现如何获取。

我写了个demo,80是写死的,我希望计算出网格单元格宽度来替换它。这样,代码更有通用性。 => demo image

HOUSHENGREN commented 1 year ago

See the demo and checkout the doc.

我想获取网格的宽度,或者网格一个单元格的宽度。通过判断文字宽度是否超过网格单元格的宽度,进而决定要不要对label数据进行位置的调整。没发现如何获取。

我写了个demo,80是写死的,我希望计算出网格单元格宽度来替换它。这样,代码更有通用性。 => demo image

大佬,有没有方法计算网格单元格宽度呢?🤦‍♂️