I'm using the horizontal bar chart for flutter that autosizes the bar heights.
https://google.github.io/charts/flutter/example/bar_charts/horizontal_bar_label.html
When I have a single bar as in this example I want to fix a maxheight (e.g. 10px) for the bar. How is this configured?
I'm looking at the constructor here but I haven't found a solution https://pub.dev/documentation/charts_flutter/latest/flutter/BarChart-class.html
child: SizedBox(
width: 300.0,
height: 250.0,
child: charts.BarChart(
[
charts.Series<OrdinalSales, String>(
id: 'Sales',
domainFn: (OrdinalSales sales, _) => sales.year,
measureFn: (OrdinalSales sales, _) => sales.sales,
data: localData,
colorFn: (_, __) =>
charts.MaterialPalette.green.shadeDefault,
labelAccessorFn: (OrdinalSales sales, _) =>
'Category 1: ${sales.sales.toString()}')
],
animate: true,
vertical: false,
barRendererDecorator: new charts.BarLabelDecorator<String>(labelPosition: charts.BarLabelPosition.inside
),
domainAxis:
new charts.OrdinalAxisSpec(renderSpec: new charts.NoneRenderSpec()),
),
),
Horizontal bar chart using the column chart typeStep 1: First, declare and initialize the chartData with the required data source. Step 2: Then, initialize the SfCartesianChart and set the isTransposed property to true. // Setting isTransposed to true to render horizontally.
You can try to wrap BarChart
in to SizedBox
, wrapped with SingleChildScrollView
.
- SingleChildScrollView
- SizedBox
- charts.BarChart
SingleChildScrollView(
child: SizedBox(
height: 2000,
child: HorizontalBarLabelChart(
getData(),
),
),
),
Height of the SizedBox
can be calculated base on number of data, e.g.:
numerOfElements * 50
For 100 elements
For 100 elements (so height is 5000
because 100 * 50
)
Try to do this -
ConstrainedBox(
constraints: BoxConstraints.expand(height: 50.0), // adjust the height here
child: Your_chart_here, // place your chart here
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With