question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: <rect> attribute height: A negative value is not valid.

See original GitHub issue

chart height is set to negative

  • when i use axios to get data from my NODE chart-api, Re-Chart is not displaying properly. it throws an error "Error: <rect> attribute height: A negative value is not valid."

  • when i remove axios and use hardcoded data, chart is rendering properly. below is my code comnponentDidMount(){ axios.get(url).then(res=>{ this.setstate({data: res.data}) }) } render(){ return !this.state.data.length ? "Loading" : ( <ComposedChart width={600} height={300} data={data} margin={{top: 20, right: 20, bottom: 0, left: 20}}> <CartesianGrid stroke='#fafafa'/> <XAxis dataKey="month"/> <YAxis /> <Tooltip /> <Legend /> <Bar dataKey='sellin' barSize={20} fill='#ec1b25' label={{ position: 'top', fill: '#ec1b25', fontSize: '10px' }}/> <Bar dataKey='sellout' barSize={20} fill='#fbce06' label={{ position: 'top', fill: '#fbce06', fontSize: '10px' }}/> <Line type='monotone' dataKey='target' stroke='#ff7300' /> </ComposedChart> ) }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
joshuagishcommented, Apr 19, 2019

I’m having the same issue but for <rect> width on the bar chart.

When the browser is resized, recharts updates the width of the bars to fill space. The issue is once it shrinks past a certain width, recharts starts inputting negative values.

1reaction
toooldmohammadcommented, Mar 31, 2020

try to put your chart inside a ResponsiveContainer and don’t forgot to set its width and height like:

import {
    ResponsiveContainer,
} from 'recharts';

<ResponsiveContainer width="100%" height={400}>
    <PieChart>
        <Pie
            data={pieChart}
            innerRadius={60}
            fill="#8884d8"
            paddingAngle={5}
            dataKey="value">
        {pieChart.map((entry, index) => <Cell key={`cell-${index}`} fill={entry.color} />)}
        </Pie>
        <Legend />
        <Tooltip />
    </PieChart>
</ResponsiveContainer>

I had this issue and fixed with ResponsiveContainer

Read more comments on GitHub >

github_iconTop Results From Across the Web

<rect> attribute height: A negative value is not valid. #2009
This error shows up on chrome and chromium but not in firefox. It doesn't affect rendering, but it's annoying to have errors in...
Read more >
D3.js Error: <rect> attribute width: A negative ... - Stack Overflow
When I close a page in my app, I get this error "Error: attribute width: A negative value is not valid. ("-100")" in...
Read more >
garnish - Error: Invalid negative value for <rect> attribute
$chartContainer in my own widget, the width is different and the height is not present. I don't see these values set explicitly in...
Read more >
Error: <rect> attribute width: A negative value is not valid
Hi,. On responsive plots, when the width is narrowed too much, an error is triggered with the message: Error: <rect> attribute width: A...
Read more >
How to Debug Error: Invalid negative value for <rect> attrib
Hello. I keep getting this error in the console: Error: Invalid negative value for <rect> attribute width="-2"
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found