flutter - 如何自动换行charts_flutter 图例?

标签 flutter legend

如何自动换行charts_flutter 图例?

当前状态:

now

预期:

aim_1 aim_2

我试过了,

  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/

相关文章:

java - jfreechart - 更改图例中的颜色样本

每个系列的 jqplot 图例控制。系列 showLabel 无法与增强图例渲染器一起使用

python - 更改主图图例标签文本

flutter - 使用 Cubit Bloc 更新另一个小部件

android - 来自 adb : Invalid argument(s): The source must not be null Error launching application on device 的 Flutter 意外失败

flutter - 没有名称为 'nullOk' 的命名参数。上下文 != null ? Localizations.localeOf(上下文,nullOk : true) : null,

visual-studio-code - Flutter Simulator-Choice Button 在 VSCode 中消失了

flutter - 多个平台的文本字段警报对话框

r - 在主标题上方放置图例

r:带有自定义图例和永久显示国名的 Choropleth