WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Issues with Horizontal Grouped Bar Chart rendering and customization #1142

@engineer-dilnawaz

Description

@engineer-dilnawaz

Description

Issues with Horizontal Grouped Bar Chart rendering and customization

Description

When trying to render a horizontal bar chart (and especially grouped ones), there are multiple problems:

  1. Auto height/width not respected → The chart does not expand to fit the parent container. Even if there’s free space on screen, the chart is cropped.
  2. Last bar cropped → In horizontal mode, the last bar is not fully visible.
  3. Gap between X-axis and chart is not controllable → The bars and X-axis labels are stuck together, and no prop exists to control this spacing.
  4. Grouped horizontal chart labels → For grouped charts, the labels should appear aligned like in the attached image, but currently this is not supported.

Minimal reproduction

import { BarChart as GiftedBarChart } from 'react-native-gifted-charts'

import { HPX } from '~app/utils'

import { HorizontalBarChartProps } from './HorizontalBarChartProps'
import { useBarChart } from './useBarChart'

export const HorizontalBarChart = (props: HorizontalBarChartProps) => {
  const { NUMBER_OF_SECTIONS, BAR_WIDTH, X_AXIS_THICKNESS, Y_AXIS_THICKNESS, BAR_COLOR, SPACING } =
    useBarChart()

  return (
    <GiftedBarChart
      hideRules
      hideOrigin
      isAnimated
      horizontal
      hideYAxisText
      disablePress
      disableScroll
      xAxisLabelTextStyle={{ color: 'white' }}
      endSpacing={200}
      labelWidth={40}
      adjustToWidth
      labelsExtraHeight={-20}
      backgroundColor={'red'}
      color={BAR_COLOR}
      xAxisThickness={X_AXIS_THICKNESS}
      yAxisThickness={Y_AXIS_THICKNESS}
      frontColor={BAR_COLOR}
      barWidth={BAR_WIDTH}
      noOfSections={NUMBER_OF_SECTIONS}
      spacing={SPACING}
      shiftX={-3}
      shiftY={-10}
      {...props}
    />
  )
}

Following is the screenshot of what I am looking for in group bar chart the xAxis Label should be right in middle of two bars

Image

Steps to reproduce

import { BarChart as GiftedBarChart } from 'react-native-gifted-charts'

export const HorizontalBarChart = (props) => {
const { NUMBER_OF_SECTIONS, BAR_WIDTH, X_AXIS_THICKNESS, Y_AXIS_THICKNESS, BAR_COLOR, SPACING } =
useBarChart()

return (
<GiftedBarChart
hideRules
hideOrigin
isAnimated
horizontal
hideYAxisText
disablePress
disableScroll
xAxisLabelTextStyle={{ color: 'white' }}
endSpacing={200}
labelWidth={40}
adjustToWidth
labelsExtraHeight={-20}
backgroundColor={'red'}
color={BAR_COLOR}
xAxisThickness={X_AXIS_THICKNESS}
yAxisThickness={Y_AXIS_THICKNESS}
frontColor={BAR_COLOR}
barWidth={BAR_WIDTH}
noOfSections={NUMBER_OF_SECTIONS}
spacing={SPACING}
shiftX={-3}
shiftY={-10}
{...props}
/>
)
}

Snack or a link to a repository

https://snack.expo.dev/@dilnawazatexpo/group-bar-chart

version of react-native-gifted-charts

1.4.63

React Native version

0.80.2

Platforms

Android, iOS

Workflow

React Native

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions