如何自动换行charts_flutter 图例?
当前状态:
预期:
我试过了,
behaviors: [charts.SeriesLegend(desiredMaxColumns: 2)],
但是,它已固定为两列。 行数和图例长度是可变的。
我应该做什么?
最佳答案
这不是开箱即用的解决方案,但您可以通过扩展 charts.LegendContentBuilder
类来创建自己的自定义图例生成器并以您认为合适的方式布局图例。
class CustomLegendBuilder extends charts.LegendContentBuilder{
@override
Widget build(BuildContext context, LegendState legendState, Legend legend, {bool showMeasures}) {
/*
Implement your custom layout logic here. You should take into account how long
your legend names are and how many legends you have. For starters you
could put each legend on its own line.
*/
return Container(
color: Colors.red,
height: 25.0,
child: Text('MY CUSTOM LEGEND'),
);
}
}
现在,当您构建图表时,添加以下行为:
...
behaviors: [
charts.SeriesLegend.customLayout(
CustomLegendBuilder(),
// Other legend properties here
),
],
...
关于flutter - 如何自动换行charts_flutter 图例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59111701/