React-native-chart-kit: renderDotContent is not aligned to dot

Created on 1 Mar 2020  路  11Comments  路  Source: indiespirit/react-native-chart-kit

My code:

            <LineChart
                data={{labels, datasets}}
                width={Dimensions.get('window').width * 0.8}
                height={220}
                chartConfig={{...}}
                bezier
                fromZero
                style={{padding: 10}}
                renderDotContent={({x, y, index}) => <Text>{y}</Text>}
            />

Results in the dot text floating without any correlation to the chart:
image

Is there any config I'm missing?

Most helpful comment

I think I solved it
Before:
Screen Shot 2020-05-19 at 08 55 30
After:
Screen Shot 2020-05-19 at 08 55 43

All 11 comments

you can use absolute to set the position of points:

Thanks, it almost works, I'm getting the render method called twice with same input but one is placed on the far left for some reason

image

the second instance just seem to ignore the style, I'm guessing if it was always there but with same style the duplicates would just hide each other

renderDotContent={({x, y, index}) => <Text style={{position: 'relative', top: y, left: x, backgroundColor: 'red'}}>{index === 0 ? `(${x}, ${y}, ${index})` : ''}</Text>}

image

Im getting the same problem even though i'm using position: 'absolute'.

My code:
renderDotContent={({ x, y }) => <Text key={x + y} style={{ position: 'absolute', top: y, left: x }}>{y}</Text>}

Screenshot 2020-04-03 at 11 03 51

@fung199609 Facing the same problem, tried position: 'absolute'.

same, have solved? :(

I think I solved it
Before:
Screen Shot 2020-05-19 at 08 55 30
After:
Screen Shot 2020-05-19 at 08 55 43

Works great thanks!

image

how did you pick the y axis value in renderDotContent?

 <LineChart
  data={{labels, datasets}}
  renderDotContent={({x, y, index}) => <DotContent key={index} x={x} y={y} value={datasets[0].data[index]}/>}
  ...
</LineChart>

None of the above worked for me. I am using version 5.6.1 and after many hours of attempts I got the following to work as needed:

import {Svg, Text as TextSVG}                                   from 'react-native-svg';

//LineChart
              //...
              bezier
              style={{
                marginLeft: chartMarginLeft,
                paddingTop: 30
              }}
              renderDotContent={({x, y, index}) => {
                return (
                      <TextSVG
                        key={index}
                        x={x}
                        y={y - 10}
                        fill="black"
                        fontSize="16"
                        fontWeight="normal"
                        textAnchor="middle">
                        {chartDataMock[index]}
                      </TextSVG>
                );
              }}

a

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azui007 picture azui007  路  6Comments

dahudson88 picture dahudson88  路  5Comments

vedika96 picture vedika96  路  4Comments

ighormartins picture ighormartins  路  3Comments

NS-BOBBY-C picture NS-BOBBY-C  路  5Comments