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

Gotchas with BarChart #4862

Open
NathanCummings opened this issue Feb 9, 2025 · 0 comments
Open

Gotchas with BarChart #4862

NathanCummings opened this issue Feb 9, 2025 · 0 comments

Comments

@NathanCummings
Copy link

NathanCummings commented Feb 9, 2025

Not so much bugs, but I had difficulty with two issues when implementing a BarChart over the past couple of days.

  1. If you don't set the x attribute on your BarChartGroups, your bottom_axis labels will be wrong and it may not be clear why.

Here is a minimal example:

import flet as ft


def main(page: ft.Page):
    chart = ft.BarChart(
        bar_groups=[
            ft.BarChartGroup(
                # x=0,
                bar_rods=[ft.BarChartRod(to_y=987.6)],
            ),
            ft.BarChartGroup(
                # x=1,
                bar_rods=[ft.BarChartRod(to_y=678.9)],
            ),
            ft.BarChartGroup(
                # x=2,
                bar_rods=[ft.BarChartRod(to_y=543.2)],
            ),
        ],
        bottom_axis=ft.ChartAxis(
            labels=[
                ft.ChartAxisLabel(value=0, label=ft.Text("Apples")),
                ft.ChartAxisLabel(value=1, label=ft.Text("Bananas")),
                ft.ChartAxisLabel(value=2, label=ft.Text("Oranges")),
            ]
        ),
        border=ft.border.all(1, ft.Colors.GREY_400),
        left_axis=ft.ChartAxis(
            labels_size=40, title=ft.Text("Fruit supply"), title_size=40
        ),
        max_y=1100,
    )

    page.add(chart)


ft.app(main)

Results in:

Image

Notice that the bottom axis labels are wrong. If you uncomment the lines setting BarChartGroup.x, the labels are correct.

  1. The other is with tooltips. I was confused as to why the first bar didn't have a tooltip, until I added the line max_y=1100 and noticed that the tooltip was simply hidden beyond the top of the chart.

Until I stripped it out from my application into this most basic form, I couldn't figure out where the problems were coming from.

It may just be me being dense, and other's wouldn't have struggled so much with this! But I thought it worth putting here in case the developers feel more clarity in the docs is warranted, or at least others with the same problem may stumble upon this. Would be a shame for people to bounce off this very useful library over niggels like this.

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

1 participant