Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineChart 设置customDataPoint不显示 #8

Open
xuxiaoqian1 opened this issue Aug 9, 2024 · 0 comments
Open

LineChart 设置customDataPoint不显示 #8

xuxiaoqian1 opened this issue Aug 9, 2024 · 0 comments

Comments

@xuxiaoqian1
Copy link
Collaborator

xuxiaoqian1 commented Aug 9, 2024

描述 / Description

问题:在harmonyOS Next中LineChart 设置customDataPoint不显示
根因:harmonyOS中Svg嵌套Text不显示。react-native-oh-library/react-native-harmony-svg#256

问题复现demo:

 import React from 'react';
import { View, Text } from 'react-native';
import { LinearGradient, Stop } from 'react-native-svg';
import { LineChart } from 'react-native-gifted-charts';

const GradientLineAndLabel = () => {
  const offset = 130;

  const customDataPointComp = v => {
    const isUp = v + offset > 175;
    const color = v + offset > 180 ? '#EA3335' : v + offset > 150 ? '#F5AF22' : '#8B943B';
    return (
      <View style={{ height: 16, width: 28, alignItems: 'center' }}>
        <Text
          style={{
            position: 'absolute',
            zIndex:100,
            top: isUp ? -20 : 15,
            color,
            fontWeight: 'bold',
            fontSize: 16,
            fontStyle: 'italic',
          }}>
          {console.log('fffff', v + offset)}
          {v + offset}
        </Text>
        <View
          style={{
            height: 16,
            width: 16,
            borderRadius: 8,
            borderWidth: 2,
            borderColor: color,
            backgroundColor: 'white',
            justifyContent: 'center',
            alignItems: 'center',
          }}>
          <View
            style={{
              height: 6,
              width: 6,
              borderRadius: 3,
              backgroundColor: color,
            }}
          />
        </View>
      </View>
    );
  };

  const dv = [
    { value: 170 },
    { value: 220 },
    { value: 170 },
    { value: 196 },
    { value: 176 },
    { value: 141 },
    { value: 172 },
  ];

  return (
    <View style={{ borderWidth: 1 }}>
      <LineChart
        data={dv}
        noOfSections={5}
        lineGradient
        lineGradientId="ggrd"
        lineGradientComponent={() => {
          return (
            <LinearGradient id="ggrd" x1="0" y1="0" x2="0" y2="1">
              <Stop offset="0" stopColor={'#EA3335'} />
              <Stop offset="0.5" stopColor={'#F5AF22'} />
              <Stop offset="1" stopColor={'#8B943B'} />
            </LinearGradient>
          );
        }}
        xAxisThickness={0}
        yAxisThickness={0}
        yAxisOffset={offset}
        customDataPoint={item => {
          return customDataPointComp(item.value);
        }}
      />
    </View>
  );
};

export default GradientLineAndLabel;

复现步骤 / Steps to reproduce

No response

库版本 / Library version

1.4.16-0.0.1

React Native OpenHarmony version

0.72.28

构建类型 / Build type

Debug app & dev bundle

设备 / Device

Real device

设备版本 / Device model

Mate 60 pro(3.0.0.29)

已悉知 / Acknowledgements

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant