Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add text on drawn shape using react-native-art?

I am drawing a pie chart using react-native-art. I want to add the text on each shape (or an arc of pie chart). Is there any way through which I can achieve this.

like image 642
Chetan Avatar asked Nov 08 '25 09:11

Chetan


1 Answers

The only way to add text inside a shape at the moment is to use Text component provided by react-native-art. It is not Text component of react-native, btw.

Positioning the text requires using of Group, another component of react-native-art.

A general example:

import { Surface, Group, Text } from 'react-native/Libraries/ART/ReactNativeART'

...
return (
  <Surface>
    <Group x={xCoord} y={yCoord}>
      <Text
        font={`13px "Helvetica Neue", "Helvetica", Arial`}
        fill = "#000000"
        alignment = "center"
      >
        Hello World
      </Text>
    </Group>
  </Surface>
)
...

EDIT: If you want to find more, please look at the temporary doc for ART library: https://github.com/react-native-china/react-native-ART-doc/blob/master/doc.md

like image 117
blaz Avatar answered Nov 09 '25 23:11

blaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!