Flutter - 堆叠在一张条形图中的水平条形图
我正在尝试实现这种类型的水平条形图堆叠在一个条形图中。我遇到了 fl_chart 包,但似乎没有一个具有我正在寻找的类型。如果任何冠军可以支持我,告诉我如何实现这一目标的步骤,或者示例代码将会非常有帮助。预先非常感谢您。
![]() |
I'm trying to achieve this type of horizontal bar chart stacked within one Bar chart. I came across the fl_chart package, but none of it seems to have the type that I'm looking for. If any champ can support me in giving me steps to how to achieve this or an exemplary code will be so much helpful. Thank you so much in advance.
![]() |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您还可以使用
LinearGradient
来实现此目的。LinearGradient 采用
List元素。颜色
和List停止。
为了获得清晰的颜色边界,您可以复制颜色并在边界处停止。
示例:
完整代码示例
You could also achieve this with a
LinearGradient
.A LinearGradient takes a
List<Color> colors
andList<double> stops
.In order to have clear color boundaries, you duplicate the colors and stops at the boundaries.
Example:
Full code sample
感谢@ChiragBargoojar 的代码,我刚刚添加了一些自定义功能,并且图表按照我的设计方式工作。
如果还有人想知道,这里是代码:
Thanks for the code @ChiragBargoojar, I just added bits of customization and the graph works as how I designed it.
If anyone else wondering, here's the code:
结果
Result
我认为,在没有任何包的情况下执行此操作的最佳和最简单的方法是使用具有相应类别百分比的 Flex 的行和扩展容器。
像这样
,我希望您的模型是一个类别模型,其进度和颜色作为该阶梯栏的属性。
I assume, the best and simplest way to do this without any packages is using row and expanded containers with flex of respective category percentages.
Like this
Here I expect your model to be a category model with progress and color as a property for this stepped bar.
有一个简单的 flutter 包:
https://pub.dev/packages/staked_horizontal_bar_chart
There is a simple flutter package for that:
https://pub.dev/packages/staked_horizontal_bar_chart