首页 > 解决方案 > 使用 fl_chart 包在线性图表中绘制底部标题时导致错误的原因

问题描述

错误说明“RangeError(索引):无效值:不在包含范围 0..11:15 内”

列表元素示例 getDays = [30 Aug, 31 Aug, 01 Sep, 02 Sep, 03 Sep, 04 Sep, 05 Sep, 06 Sep, 07 Sep, 08 Sep, 09 Sep, 10 Sep]

较短的列表会导致错误。但是更长的列表也没关系。

 bottomTitles: SideTitles(
          showTitles: true,
          reservedSize: 5,
          textStyle: const TextStyle(
              color: Color(0xff68737d),
              fontSize: 12,
              fontWeight: FontWeight.bold),
          getTitles: (value) {
            //value from x point
            if (value.toInt() % 5 == 0) {
              return '${widget._healthPresenter.getDays[value.toInt()]}';
            }
            return '';
          },
          margin: 10,
        )

标签: flutterfl-chart

解决方案


推荐阅读