简体   繁体   English

如何修复颤动水平条形图中条形的高度

[英]how to fix the height of bars in flutter horizontal bar charts

In flutter charts, the horizontal chart automatically stretches according to the height of the screen.在颤动图中,水平图会根据屏幕的高度自动拉伸。 Is there any way through which I may fix the height of the bars so that it may not stretch to the entire screen?有什么方法可以固定条形的高度,使其不会延伸到整个屏幕?

Simple add your chart in the ConstrainedBox like this -像这样简单地在 ConstrainedBox 中添加您的图表 -

ConstrainedBox(
  constraints: BoxConstraints.expand(height: 200.0), // give the height according to you
   child : Your_Chart_here(), // your chart here
),

You can try to wrap BarChart in to SizedBox (to set size), wrapped with SingleChildScrollView (to scroll it).您可以尝试将BarChart包装到SizedBox (设置大小),用SingleChildScrollView包装(滚动它)。

In pseudocode在伪代码中

- SingleChildScrollView
       - SizedBox
              - charts.BarChart

Flutter

SingleChildScrollView(
  child: SizedBox(
    height: 2000,
    child: HorizontalBarLabelChart(
      getData(),
    ),
  ),
),

Size calculation尺寸计算

Height of the SizedBox can be calculated base on number of data, eg: SizedBox高度可以根据数据的数量计算,例如:

numerOfElements * 50

Before

For 100 elements对于 100 个元素

在此处输入图片说明

After

For 100 elements (so height is 5000 because 100 * 50 )对于 100 个元素(所以高度是5000因为100 * 50

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM