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

BarChart - Value and section line don't match #35

Closed
fleuverouge opened this issue Nov 18, 2021 · 4 comments
Closed

BarChart - Value and section line don't match #35

fleuverouge opened this issue Nov 18, 2021 · 4 comments

Comments

@fleuverouge
Copy link

Hi,
Thanks for this amazing package. However, I'm facing this issue with the BarChart component:
Please check this image for more comprehensive: Screenshot
The bars' values are 3 and 6, but their tops don't reach the relevant section lines.

@Abhinandan-Kushwaha
Copy link
Owner

Hi @fleuverouge Can you share the Code here?

@Abhinandan-Kushwaha
Copy link
Owner

Abhinandan-Kushwaha commented Nov 18, 2021 via email

@fleuverouge
Copy link
Author

fleuverouge commented Nov 18, 2021

Hi @Abhinandan-Kushwaha ,
Thanks for replying
I had trouble with making a bar's label displayed fully with center-x alignment in small screens (like in the picture), so for each bar, I created 2 "mock" bars.

Here's my code:

Sizes calculation:

        const barWidth = width * 0.1;
        const labelWidth = width * 0.18;
        const mockBarWidth = (labelWidth - barWidth) / 2;

adjustedData: ( calculating this is a complicated process from our raw data, so I just pasted the output here)

[
   {
      "value":3,
      "spacing":0,
      "label":"Physics",
      "labelWidth":87,
      "frontColor":"rgba(0,0,0,0)",
      "barWidth":26.099999999999998,
      "labelTextStyle":{
         "color":"black",
         "fontSize":12
      }
   },
   {
      "value":3,
      "frontColor":"green",
      "spacing":0,
      "barWidth":34.800000000000004
   },
   {
      "value":3,
      "barWidth":26.099999999999998,
      "frontColor":"rgba(0,0,0,0)",
      "spacing":3.48
   },
   {
      "value":6,
      "spacing":0,
      "label":"Mathematics",
      "labelWidth":87,
      "frontColor":"rgba(0,0,0,0)",
      "barWidth":26.099999999999998,
      "labelTextStyle":{
         "color":"black",
         "fontSize":12
      }
   },
   {
      "value":6,
      "frontColor":"black",
      "spacing":0,
      "barWidth":34.800000000000004
   },
   {
      "value":6,
      "barWidth":26.099999999999998,
      "frontColor":"rgba(0,0,0,0)",
      "spacing":3.48
   }
]
<BarChart
                        backgroundColor={colors.white}
                        height={chartHeight}
                        noOfSections={3}
                        barBorderRadius={0}
                        data={adjustedData}
                        isAnimated
                        disablePress
                    />

@Abhinandan-Kushwaha
Copy link
Owner

Hi @fleuverouge
You can solve this issue by using the maxValue and stepValue props.
Try passing maxValue = {9}

Detailed inspection of the issue -

  • Since the data includes values 3 and 6, it sets the maxValue = 10 (multiple of 10 next to the biggest value).
  • And then since, you have passed noOfSections = 3 , each section height becomes 3.333....
  • And, the labels appearing on y-axis are rounded figures, so the 3 that you see on y-axis is not actually 3, instead it's a rounded value of 3.333... (You can disable rounding by using the showFractionalValues prop.)

Note -
Whenever we use the noOfSections we must passstepValue and maxValue also.

It's mentioned in the documents here-
BarChartProps.md

Hope it solves your issue. Cheers! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants