react-native-chart-kit icon indicating copy to clipboard operation
react-native-chart-kit copied to clipboard

Centering PieChart

Open bberak opened this issue 6 years ago • 6 comments

Hi there,

Thanks for maintaining this project - it looks really great :)

Is it possible to center the PieChart? Mine a bit off-center

I'm using v4.1.0 and my code is below:

<ProgressChart
              data={{
                data: [0.4]
              }}
              width={100}
              height={100}
              chartConfig={{
                backgroundColor: "#e26a00",
                backgroundGradientFrom: "#fb8c00",
                backgroundGradientTo: "#ffa726",
                decimalPlaces: 2, // optional, defaults to 2dp
                color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
                labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
                style: {
                  borderRadius: 16
                },
                propsForDots: {
                  r: "6",
                  strokeWidth: "2",
                  stroke: "#ffa726"
                }
              }}
              hideLegend={true}
            />

Cheers!

bberak avatar Dec 10 '19 04:12 bberak

The hideLegend implementation is pretty basic and does not support this right now. Fixing this would be an awesome PR!

Hermanya avatar Dec 10 '19 04:12 Hermanya

Cool, I'll take a look - cheers!

bberak avatar Dec 10 '19 04:12 bberak

Anything new about this?

laurpantelimon avatar Jul 14 '20 09:07 laurpantelimon

anything new about this ?

amineba1 avatar May 15 '21 23:05 amineba1

found a temporary solution: style={{marginLeft:'auto',marginRight:'auto',left:0,right:0}}

wscld avatar Oct 26 '21 22:10 wscld

Try this:

<PieChart
   width={220}
   height={220}
   center={[50, 0]}

   data={summary_chart}
   hasLegend={false}
   chartConfig={{
      color: (opacity = 1) => `rgba(0, 0, 0, ${opacity})`,
   }}
   accessor="population"
   backgroundColor="transparent"
   paddingLeft="0"
   absolute
/>

By using the center prop, you can control the chart's position within its container. Combine this with fixed width and height to achieve the desired layout.

yurischulz avatar Aug 08 '24 02:08 yurischulz