Code Monkey home page Code Monkey logo

Comments (4)

Abhinandan-Kushwaha avatar Abhinandan-Kushwaha commented on May 23, 2024

Hi @fleuverouge Can you share the Code here?

from react-native-gifted-charts.

Abhinandan-Kushwaha avatar Abhinandan-Kushwaha commented on May 23, 2024

from react-native-gifted-charts.

fleuverouge avatar fleuverouge commented on May 23, 2024

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
                    />

from react-native-gifted-charts.

Abhinandan-Kushwaha avatar Abhinandan-Kushwaha commented on May 23, 2024

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! 🎉

from react-native-gifted-charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.