•  


Pie charts from recharts are not responsive. · Issue #1136 · recharts/recharts · GitHub
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

Pie charts from recharts are not responsive. #1136

Open
Mujtaba4ahmed opened this issue Jan 11, 2018 · 16 comments
Open

Pie charts from recharts are not responsive. #1136

Mujtaba4ahmed opened this issue Jan 11, 2018 · 16 comments
Labels
bug General bug label enhancement Enhancement to a current API P1 High priority issues

Comments

@Mujtaba4ahmed
Copy link

I used the recharts in my application. On changing the window size, the charts are not responsive at all. They are coming out of my div in which I put them(Piecharts).

@drj17
Copy link

Have you wrapped your chart in a responsive container?

@Mujtaba4ahmed
Copy link
Author

Mujtaba4ahmed commented Jan 16, 2018 via email

@christiancho
Copy link

Can you share your code?

@Mujtaba4ahmed
Copy link
Author

Mujtaba4ahmed commented Jan 18, 2018 via email

@christiancho
Copy link

christiancho commented Jan 18, 2018

PLEASE make sure you use proper MD formatting for code so that it's properly formatted.

You're not using ResponsiveContainer (did you click the link that @drj17 shared?). Additionally, you can clean up your code by using react-bootstrap as well:

<Col md={2} sm={3} xs{3}>
  <ResponsiveContainer height={150} width="100%">
    <PieChart>
      <Pie
        data={this.props.graphData.tech}
        dataKey='value'
        innerRadius={35}
        outerRadius={50} startAngle={90} endAngle={450}
      >
        {this.props.graphData.tech.map((entry, index) => (
          <Cell fill={COLORS[index % COLORS.length]} />\
        )}
      </Pie>
      <Tooltip />
    </PieChart>
  </ResponsiveContainer>
</Col>

In the future, I suggest you look through documentation and the examples to see how responsiveness is handled.

@giokokos
Copy link

Please check my jsfiddle at #675 I have a similar issue.

@NetaLev
Copy link

@Mujtaba4ahmed

Also try using percentage instead of fixed numbers in innerRadius and outerRadius

@breadadams
Copy link

This issue can be closed, PieChart is 100% responsive ??. Here's a stripped down working example:

const
 EXAMPLE_DATA
 =
 [

  {

    name
: 
'example1'
,

    value
: 
23.4
,

  }
,

  {

    name
: 
'example2'
,

    value
: 
76.6
,

  }
,

]
;


<
ResponsiveContainer
 width
=
"100%"
 height
=
{
154
}
>

  <
PieChart
>

    <
Pie
 data
=
{
EXAMPLE_DATA
}
 innerRadius
=
"90%"
 outerRadius
=
"100%"
 fill
=
"#ff0000"
 paddingAngle
=
{
5
}
 /
>

  <
/
PieChart
>

<
/
ResponsiveContainer
>

Resulting in the following:

image

When the parent container is <= 154px (in this case), you'll see the Pie chart begin to scale down:

image

@muhammadkashifdev
Copy link

This issue still pending PieChart is not responsive. @breadadams You use fixed height, width and height can not increase or decrease with responsive grid columns. So it is not not responsive

@xAlstrat
Copy link

xAlstrat commented Feb 4, 2020

A css hotfix I'm using for this. The relevant part is the margin, padding and vertical centering. This keeps the chart height at 600px but works.

<Grid
        item
        xs={12}
        style={{
          height: "0",
          marginTop: "50%",
          paddingBottom: "50%",
          display: "flex",
          alignItems: "center"
        }}
      >
        <ResponsiveContainer width={"100%"} height={600}>
            ...
        </ResponsiveContainer>
</Grid>

@xile611
Copy link
Member

Sorry for not handling your issue in time, please try the latest version. If the problem persists, please open a new issue according to the issue guide.

@ukozdan
Copy link

ukozdan commented Mar 26, 2020

This is still an issue. The SVG is not scaling with its HTML container and is failing on unit tests reporting zero width and height. Responsive SVG is achieved by removing the SVG width and height attributes on the svg element and only specifying width and height within the viewBox attribute. A global CSS style of svg {width: 100%;height: auto;} does the rest.
Recharts currently produces absolutely positioned paths prefixed with M and suffixed with Z . The specs specify a lower case m and z for relative paths.
Because Recharts is not allowing SVG to scale as a whole, text elements don't scale.

@hassanharoon321
Copy link

@christiancho you were amazing save my day

@ckifer
Copy link
Member

Going to re-open this as it seems it was closed while still an issue

@ckifer ckifer reopened this Jan 3, 2023
@ckifer ckifer added bug General bug label enhancement Enhancement to a current API P1 High priority issues labels Jan 3, 2023
@pchaganti
Copy link

This is still an issue.

@bryanjtc
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment
Labels
bug General bug label enhancement Enhancement to a current API P1 High priority issues
Projects
None yet
Development

No branches or pull requests

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본