React-native-chart-kit: Show Y values over each dot (Line Chart)

Created on 12 Nov 2019  路  5Comments  路  Source: indiespirit/react-native-chart-kit

Hi!

I'm working on a Line Chart with dots and I would like to render each dot's respective Y value over them. Can you please provide a decorator implementation to do so? I just need the values to be wrapped in a node, nothing fancy.

Thanks in advance!

Most helpful comment

Just incase anyone looks at this in the future and wants a really quick and dirty way to do this, update your line graph as:

renderDotContent={({ x, y, index }) => {
            return (
              <View
                style={{
                  height: 24,
                  width: 24,
                  backgroundColor: "#abc",
                  position: "absolute",
                  top: y - 36, // <--- relevant to height / width (
                  left: x - 12, // <--- width / 2
                }}
              >
                <Text style={{ fontSize: 10 }}>{data[index]}</Text>
              </View>
            );
          }}

will produce something that looks like:
Screenshot 2020-08-20 at 14 19 00

All 5 comments

I'm not sure if this is a common pattern. I haven't had such a feature request so far. Try forking this repo. If you think you can make a great API for this, I'd welcome a PR.

My bad. What I meant was that I would like to know if someone could point me in the right direction to use the decorator to render simple text over each dot of the chart. I mean something similar to this: https://github.com/indiespirit/react-native-chart-kit/issues/160 but rendering each respective dot's Y value over it:

2019-11-11_23-56-06

Thanks again.

Just incase anyone looks at this in the future and wants a really quick and dirty way to do this, update your line graph as:

renderDotContent={({ x, y, index }) => {
            return (
              <View
                style={{
                  height: 24,
                  width: 24,
                  backgroundColor: "#abc",
                  position: "absolute",
                  top: y - 36, // <--- relevant to height / width (
                  left: x - 12, // <--- width / 2
                }}
              >
                <Text style={{ fontSize: 10 }}>{data[index]}</Text>
              </View>
            );
          }}

will produce something that looks like:
Screenshot 2020-08-20 at 14 19 00

indexData is simpler

          renderDotContent={({x, y, indexData}) => (
            <View
              style={{
                position: 'absolute',
                top: y - 25,
                left: x - 8,
              }}>
              <Text style={{fontSize: 10}}>
                {indexData}
              </Text>
            </View>
          )}
Was this page helpful?
0 / 5 - 0 ratings