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

Added .fromItem constructor to BarChart #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matheus-kirchesch
Copy link

I did this to allow me to use the CharItem value from the data: property in the BarChart, example:

return BarChart.fromItem(
      data: [
        ChartItem(32.52, value: {
          'title': 'De 1 á\n16 dias',
          'value': '32.52',
        }),
        ChartItem(15.8, value: {
          'title': 'De 16 á\n30 dias',
          'value': '15.8',
        }),
        ChartItem(15.97, value: {
          'title': 'De 31 á\n60 dias',
          'value': '15.97',
        }),
      ],
      itemOptions: WidgetItemOptions(
        widgetItemBuilder: (data) {
          print(data.item);

          return Container(
            decoration: BoxDecoration(
              color: Theme.of(context).colorScheme.primary,
            ),
            margin: EdgeInsets.symmetric(horizontal: 4.0),
            child: RotatedBox(
              quarterTurns: 1,
              child: Align(
                alignment: Alignment.centerLeft,
                child: Padding(
                  padding: const EdgeInsets.symmetric(
                    vertical: 2.0,
                    horizontal: 8.0,
                  ),
                  child: Text('${data.item.max}%'),
                ),
              ),
            ),
          );
        },
      ),
    );

In this example I can use my custom property 'title' to dynamically draw it while rendering the bar.

Without this the only thing I have from my ChartItem is the max property, and it also makes the API simpler.

@matheus-kirchesch
Copy link
Author

In the commit I also included the change from BarValue to ChartValue since BarValue has been deprecated, since it was a small change I decided to include in the same pull request.

@lukaknezic lukaknezic self-requested a review June 15, 2023 09:06
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

Successfully merging this pull request may close these issues.

1 participant