[英]How do I set the max height on a Flutter Horizontal Bar Chart?
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 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 (eg 10px) for the bar.当我在这个例子中只有一个栏时,我想为栏固定一个最大高度(例如 10px)。 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我在这里查看构造函数,但我还没有找到解决方案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()),
),
),
There is no possibility to do this for the moment according to this issue .根据此问题,暂时无法执行此操作。
But I think you can bypass this by creating others items with transparent color or change the Chart library code.但我认为您可以通过创建具有透明颜色的其他项目或更改图表库代码来绕过这一点。
2021/03/23
2021/03/23
There is still no solution from the google team but Boken's solution seems to be a good one.谷歌团队仍然没有解决方案,但博肯的解决方案似乎是一个很好的解决方案。
Try to do this -尝试这样做 -
ConstrainedBox(
constraints: BoxConstraints.expand(height: 50.0), // adjust the height here
child: Your_chart_here, // place your chart here
),
You can try to wrap BarChart
in to SizedBox
, wrapped with SingleChildScrollView
.您可以尝试将
BarChart
包装到SizedBox
,并用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, eg: SizedBox
高度可以根据数据的数量计算,例如:
numerOfElements * 50
For 100 elements对于 100 个元素
For 100 elements (so height is 5000
because 100 * 50
)对于 100 个元素(所以高度是
5000
因为100 * 50
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.