Flutter, How to create a clickable bar in a BarChart widget?
Use selectionModels
array property of BarChart
Widget:
new charts.BarChart(
createSampleData(),
animate: true,
barGroupingType: charts.BarGroupingType.stacked,
selectionModels: [
new charts.SelectionModelConfig(
type: charts.SelectionModelType.info,
changedListener: _onSelectionChanged,
)
],
barRendererDecorator:
new charts.BarLabelDecorator<String>(),
domainAxis: new charts.OrdinalAxisSpec(),
),
_onSelectionChanged(charts.SelectionModel model) {
final selectedDatum = model.selectedDatum;
if (selectedDatum.isNotEmpty) {
setState(() {
print(selectedDatum.first.datum.sales);
});
}
}
Ramin Bateni
I'm a idea maker & full stack developer who like using both of art & logic beside together to create innovations!😎 Since 2011, I have played in various roles (cto, team lead, full stack developer, product manager, founder, consultant &...), while I started designing applications & programming since 2004 and I was doing art design for a long time before it. - Web Developing ASP.NET MVC Core / C#.NET / Rest API / EF / Code First HTML5 / CSS3 / JavaScript / jQuery / Typescript Next.js / Vue.js / Vuex / Nuxt.js Nest.js / Node.js / Chat Bot SQL Server / Redis / MongoDB and more..... - Desktop App: C# WPF Electron - Creativity, Idea making & growing Startups - Graphic - Branding, Digital Marketing
Updated on December 24, 2022Comments
-
Ramin Bateni over 1 year
I have a flutter App and need a Bar chart in which I can click bars to open new page with related information. How should I do it?
/// Bar chart example charts.BarChart( createSampleData(), animate: true, barGroupingType: charts.BarGroupingType.stacked, barRendererDecorator: new charts.BarLabelDecorator<String>(), domainAxis: new charts.OrdinalAxisSpec(), ),