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.

Bar width for BarChart has wrong width until something triggers re-render

See original GitHub issue

Chart after triggering re-render Chart before triggering re-render Hello,

I have following data and chart:

const platformProductData = {
    keys: ['CPU', 'Storage', 'Hosting', 'Email'],
    chartData: [
      {
        platform: 'Plesk',
        CPU: 2000,
        Storage: 1000,
        Hosting: 1500,
        Email: 1500
      },
      {
        platform: 'Odin',
        CPU: 1000,
        Storage: 800,
        Hosting: 1500,
        Email: 3000
      },
      {
        platform: 'Interworks',
        CPU: 1000,
        Storage: 3000,
        Hosting: 2500,
        Email: 1800
      }
    ]
  };
<ResponsiveBar
      theme={chartTheme}
      data={data.chartData}
      keys={data.keys}
      indexBy={indexBy}
      padding={0.2}
      margin={{ top: 10, right: 10, bottom: 70, left: 10 }}
      valueFormat=" >-$.2d"
      colors={{ scheme: 'blue_green' }}
      borderColor={{
        from: 'color',
        modifiers: [['darker', 1.6]]
      }}
      labelTextColor={{
        from: 'color',
        modifiers: [['darker', 1.6]]
      }}
      legends={[
        {
          dataFrom: 'keys',
          anchor: 'bottom',
          direction: 'row',
          justify: false,
          translateX: 0,
          translateY: 70,
          itemsSpacing: 2,
          itemWidth: 100,
          itemHeight: 20,
          itemDirection: 'left-to-right',
          itemOpacity: 0.85,
          symbolSize: 20,
          effects: [
            {
              on: 'hover',
              style: {
                itemOpacity: 1
              }
            }
          ]
        }
      ]}
    />

The issue I’m facing is that bar widths are not rendered correctly until some trigger is not fired which affects their state (like changing application theme mode from light to dark through UI or changing data through code). Any suggestions? I’m using a lot of different charts on that page (sunburst, chord…) and they do not show this behavior, however, both bar charts on the page are having this issue. Data are fake and local, they are not rendered from server if that helps. Images are attached

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
jonasbjoraltcommented, Jun 21, 2022

Had the same problem, but fixed it by setting animate={false}

2reactions
rade-tomoviccommented, Jun 19, 2022

In the meantime, this is helping me getting fully rendered chart, just put it on the page where you are using your barchart (you will even get animated render 💯 :

const [count, setCount] = useState(0);

useEffect(() => {
    setTimeout(() => {
      setCount((prevCount) => prevCount + 1);
    }, 100);
  }, []);
Read more comments on GitHub >

github_iconTop Results From Across the Web

SSRS bar/range chart rendering incorrectly when amount of ...
We're experiencing some problems using a bar/range chart in SSRS. ... The report shows the performance data for a specific machine.
Read more >
reportviewer bar chart, bar width incorrect - sql - Stack Overflow
The problem is that the bars are wider then they should be. Each bar should be as width as 1 hour. The x-axis...
Read more >
Charts aren't full-size until page is refreshed - CanvasJS.com
I'm using some charts in a 3dcart-hosted site. When the page is first loaded, the charts don't load full-size.
Read more >
Visualization: Pie Chart - Google Developers
Width of the third bar in the first series of a bar or column chart: cli.getBoundingBox('bar#0#2').width; Bounding box of the fifth wedge of...
Read more >
Bar Charts: The Good, the Bad, and the Ugly - Biztory
With powerful visual analytics tools at the ready, we're capable of building dashboards at high speed and with great diversity in terms of...
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