react-native-echarts icon indicating copy to clipboard operation
react-native-echarts copied to clipboard

SvgChart doesn't renders scrollable legend properly in Android

Open guri8751 opened this issue 2 years ago • 23 comments

We are using SvgChart renderer from the package imported like this:

import SvgChart, { SVGRenderer } from '@wuba/react-native-echarts/svgChart';

When we render a chart with a legend without adding the "type" to "scroll", it displays the legend fine. But if we add the scrolling attribute in the legend configuration of the chart, it doesn't displays the legend properly and just shows it half. And when we press on the right arrow to scroll, the legend becomes completely invisible. This issue is only seen in Android and it works perfectly fine in iOS with everything same. Also, one thing to note that SkiaChart renderer doesn't have this issue at all either in Android or iOS but cannot use that because of it's huge size and drastically increased build time.

Screenshot 2023-07-11 at 10 16 00 am

guri8751 avatar Jul 11 '23 00:07 guri8751

Also have this problem when the legend's orient is set to vertical?

  legend: {
    type: 'scroll',
    orient: 'vertical',
    right: 10,
    top: 20,
    bottom: 20,
    data: data.legendData
  },

zhiqingchen avatar Jul 11 '23 11:07 zhiqingchen

Try commenting out this code to see if this is the effect here: lib/module/svgChart.js

  // fix: https://github.com/react-native-svg/react-native-svg/issues/983
  if (attrs.clipPath && !attrs.clipRule && Platform.OS === 'android') {
    attrs.clipRule = 'nonzero';
  }

zhiqingchen avatar Jul 11 '23 11:07 zhiqingchen

Hi @zhiqingchen,

  1. Changing the orientation to vertical does show them vertically but there is no scrolling functionality then and it acquires a lot of space as well which is not adequate for our needs.
  2. I tried out your suggestion and commented the code you specified. On commenting the code, the legend is shown properly at first. But the line graph disappears from the chart and once I press the arrow to scroll to the right, the legend disappears completely then and doesn't reappear at any stage.

guri8751 avatar Jul 12 '23 00:07 guri8751

Yes, we found this problem too, let me think about how to fix it.

zhiqingchen avatar Jul 12 '23 03:07 zhiqingchen

There's no good way to fix it yet, in your scenario, with a temporary patch.

  // fix: https://github.com/react-native-svg/react-native-svg/issues/983
  if (Platform.OS === 'android' && attrs.clipPath && !attrs.clipRule) {
    const allChildrenIsLine = children?.every((child) => {
      const d = child.attrs.d?.toString() || '';
      return (
        child.tag === 'path' &&
        child.attrs.fill === 'none' &&
        d[d.length - 1] !== 'Z'
      );
    });
    if (allChildrenIsLine) {
      attrs.clipRule = 'nonzero';
    }
  }

Also skia has better performance when tested and is more recommended.

zhiqingchen avatar Jul 12 '23 05:07 zhiqingchen

Hi @zhiqingchen, the temporary patch that you suggested seems to work as expected. As you're now aware of the issue, are you planning to put this patch or a different permanent fix in the next release? Thanks :)

guri8751 avatar Jul 13 '23 00:07 guri8751

If there is no more suitable method, this patch will be adopted soon.

zhiqingchen avatar Jul 13 '23 02:07 zhiqingchen

@iambool 1.2.2-alpha.3

zhiqingchen avatar Jul 13 '23 02:07 zhiqingchen

我更换了用Skia来渲染,然后遇到中文乱码的问题,然后寻找中文乱码的解决方法,提示用SVG渲染或设置字体,然后我去设置字体,在安卓上感觉没效果呀

TomWq avatar Jul 31 '23 03:07 TomWq

image https://github.com/wuba/taro-playground/blob/main/src/pages/explore/charts/pages/bar/mixTimelineFinance.tsx

  1. 尝试将依赖,升级到最新版
  2. 可能有某些系统/机型不支持,未全面验证过

zhiqingchen avatar Jul 31 '23 03:07 zhiqingchen

我设置了下全局的字体 ,现在使用的是Skia渲染, ios上一切正常,在安卓上好像不生效,还是乱码,但是使用SVG渲染就可以,我不知道我的代码哪里写的有问题 ,我还需要做哪些修改才可以呢 亲亲 { series:[ { type:'bar', showBackground:false, data: array.map((item) => item.count), barWidth: 22, axisTick: { alignWithLabel: true }, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#2378f7' }, { offset: 0.7, color: '#2378f7' }, { offset: 1, color: '#83bff6' } ]), borderType:'dashed', borderRadius: [2, 2, 0, 0] },

              label:{
                show:true,
                fontSize:8
              }
            }
          ],
          tooltip: {
            trigger: 'axis',
            showDelay: 0, 
            show: true,
            axisPointer: {
              type: 'shadow',
              shadowStyle: {
                color: 'rgba(247, 54, 93, 0.04)',
                width: '1',
              },
            },
            backgroundColor: 'rgba(0,0,0,0.7)',
            formatter: function (params) {
              // onChange(params,array)
              return params[0].name + ': ' + params[0].value;
            },
            borderWidth: 0,
            extraCssText: 'box-shadow: 0 0 3px rgba(0, 0, 0, 0);',
            textStyle: {
              color: '#fff',
          
            }
          },
          yAxis: {
            type: 'value',
            show:false
          },
          xAxis: {
            type: 'category',
            data: array.map((item) => item.showTime),
            axisLine :{
              lineStyle:{
                color:'#888',
             
              }
            },
            nameLocation:'start',
            nameTextStyle:{
              color:'#888',
              fontSize:8,
             
            },
            axisTick:{
              show:false
            },
            axisLabel:{
              color:'#888',
              fontSize:8,
             
            }
          },
          textStyle:{
            fontFamily:'monospace'
          }

}

TomWq avatar Jul 31 '23 06:07 TomWq

我用你提供的示例的代码,放到我的项目里允许也是乱码

TomWq avatar Jul 31 '23 06:07 TomWq

Is there any fix available now?

Manikanta-GEP avatar Sep 05 '23 11:09 Manikanta-GEP

@zhiqingchen Is that patch available now in 1.2.3?

Manikanta-GEP avatar Sep 08 '23 08:09 Manikanta-GEP

@zhiqingchen Is that patch available now in 1.2.3?

no, it's not final solution.

zhiqingchen avatar Sep 08 '23 10:09 zhiqingchen

我通过 将 react-native-skia 升级至 0.1.216 版本,并通过 自定义字体解决了中文乱码问题, 目前在 华为平板、oneplus、oppo 上测试没问题

xSmile-art avatar Nov 03 '23 02:11 xSmile-art

我通过 将 react-native-skia 升级至 0.1.216 版本,并通过 自定义字体解决了中文乱码问题, 目前在 华为平板、oneplus、oppo 上测试没问题

@xSmile-art 你使用的是什么字体?

zhiqingchen avatar Nov 03 '23 02:11 zhiqingchen

Hi, i'm using react-native-echarts 1.2.5 with react-native-svg 12.1.1 get exactly same issue, but my project unable to install Skia for replacing Svg. is there a solution for temporary fix ?

2024-01-16 17 10 57

NguyenHoangMinhkkkk avatar Jan 16 '24 10:01 NguyenHoangMinhkkkk

@zhiqingchen 你好,给您发了邮件,有空查收下

shenxiang216 avatar Jan 31 '24 11:01 shenxiang216

my chart is wrapped in Scrollview and and tooltip disturb when I starting touching the chart to see the tooltip it start little bit scrolling

zaidqureshi95 avatar Mar 06 '24 16:03 zaidqureshi95

my chart is wrapped in Scrollview and and tooltip disturb when I starting touching the chart to see the tooltip it start little bit scrolling

try use RNGH,https://wuba.github.io/react-native-echarts/docs/advanced-guides/use-rngh

zhiqingchen avatar Mar 07 '24 02:03 zhiqingchen