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.

Labels not re-rendering correctly when data changes.

See original GitHub issue

What is the problem?

Labels and XAxis not re-rendering properly when the data changes. The old values are still visible, overlapping the new ones.

Before data changes: (ok)

simulator screen shot - iphone 6 - 2018-05-07 at 11 57 03

After:

simulator screen shot - iphone 6 - 2018-05-07 at 11 57 44

When does it happen?

When the data changes and the chart re-renders.

Code to reproduce

renderPeriodoBar() {

        if (this.props.dashboard.caseVolume) {

            console.log('DASH',this.props.dashboard.caseVolume);

            const values = [10,20,30,40];
            const labels = ["A","B","C","D"];

            const axesSvg = { fontSize: 10, fill: this.colors.secondary_text, textAlign: 'center' };
            const verticalContentInset = { top: 10, bottom: 10 }
            const xAxisHeight = 25;

            var max = Math.max(...values);

            const Labels = ({ x, y, bandwidth, data }) => (
                data.map((value, index) => (
                    <T
                        belowChart={true}
                        key={index}
                        y={y(value) - 10}
                        x={x(index) + (bandwidth / 2)}
                        fontSize={10}
                        font={{
                            fontFamily: 'Roboto-Light',
                        }}
                        fontData={{ name: 'Roboto-Light' }}
                        fill={this.colors.secondary_text}
                        alignmentBaseline={'middle'}
                        textAnchor={'middle'}>
                        {value}
                    </T>
                ))
            )

            return (
                <View style={{ height: 180, paddingTop: 12, flexDirection: 'row' }}>
                    <View style={{ flex: 1, marginLeft: 0 }}>
                        <BarChart
                            data={values}
                            style={{ flex: 1 }}
                            gridMin={0}
                            gridMax={max * 1.5}
                            contentInset={{ verticalContentInset }}
                            svg={{
                                fill: this.colors.accent,
                                opacity: 0.80,
                            }}>
                            <Labels belowChart={true} />
                        </BarChart>
                        <XAxis
                            style={{ marginTop: 6, height: xAxisHeight }}
                            data={values}
                            scale={scale.scaleBand}
                            formatLabel={(value, index) => labels[index]}
                            svg={axesSvg}
                        />
                    </View>
                </View>)
        }
}

render(){
    return(
         <View>
         {this.renderPeriodoBar()}
        </View>
     )
}

Just call the above function on the render method, then change the data inside the function and re-render

What platform?

  • [X ] iOS 11

React Native version: 0.54.3

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
AndrePechcommented, May 8, 2018

it is updated o/

Let me know if you need something more! Thank you very much for maintaining this awesome repo!!

0reactions
animaonlinecommented, Sep 2, 2018

This should be reopened as this still happens, and can easily be reproduced

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - ChartJS not rendering after update
I recreate the chart. It's not good practice but a quick fix. The this.chart.update() does not work for me either. – Maihan Nijat....
Read more >
Rerendered Inputfield Label Not Displaying (VF)
Hello, I am trying have an inputfield render based upon what a user selects on another picklist field. The new field is rendering,...
Read more >
ASP.NET Core Razor component rendering - Blazor
Therefore, ComponentBase can only trigger rerendering when the Task is first returned and when the Task finally completes. The framework can't ...
Read more >
Updating the Data for an LWC lightning-datatable isn't re- ...
My guess is that the table doesn't know to update because you have specified a key field of id but you have not...
Read more >
A Story of a React Re-Rendering Bug - Engineering Blog
When we find a bug, no matter how tricky it is, ... /><span data-mce-type= "bookmark" style= "display: inline-block; width: 0px; ...
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