【问题标题】:charts_flutter - How to change the Bar Color automaticallychart_flutter - 如何自动更改条形颜色
【发布时间】:2020-11-04 08:29:26
【问题描述】:

我正在使用 charts_flutter 插件,但在更改图表中的条形颜色时遇到问题 有没有办法在不硬编码的情况下自动更改图表中条形的颜色?因为我的图表数据是灵活的,你不能硬编码它的颜色。

这是我为图表添加图例和数据的方式

代码:

 _list.add(new RedeemedToday.fromJson(valueMap));
    
        newLegends.add(charts.Series<RedeemedToday, String>(
          id: '${redeemedToday[index].couponName}',
          data: _list,
          domainFn: (RedeemedToday sales, _) =>
              xValue(redeemedToday[index].whenAdded.toString()),
          measureFn: (RedeemedToday sales, _) => redeemedToday[index].total,
        ));

这是默认颜色的样子:

我想要这样的彩色:

【问题讨论】:

    标签: flutter dart charts


    【解决方案1】:

    你能在 newLegends.add() 中设置 colorFn: (_,__)=>charts.ColorUtil.fromDartColor(blue)

    经验:

    Can you set **colorFn**: (_,__)=>charts.ColorUtil.fromDartColor(blue) in newLegends.add()
    
    
    Exp: _seriesData.add(
            charts.Series(
              data: data1,
              domainFn: (Pollution pollution,_)=> pollution.place,
              measureFn: (Pollution pollution,_)=> pollution.quality,
              id: 'Colum Charts SSE',
              fillPatternFn: (_,__)=>charts.FillPatternType.solid,
              colorFn: (_,__)=>charts.ColorUtil.fromDartColor(orange),// Legend color
             fillColorFn: (Pollution pollution,_)=> charts.ColorUtil.fromDartColor(orange), //column color.
            )
        );
    
    I hope, this is help you.

    希望对您有所帮助。[在此处输入图片描述][1]

    => 这是结果:[1]:https://i.stack.imgur.com/nazTx.jpg

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 2012-11-01
      • 2013-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      相关资源
      最近更新 更多