Premium Line
Premium Line

Reputation: 11

How to change the default color palette for charts in flutter?

I use charts_flutter to create charts. I know how to change the color, but I like to change the color palette. The default palette seems to be "blue". For example in a pie chart, charts_flutter uses different shades of blue. I like to use deeporange as the default palette for all kind of charts. Is there a way to change it?

Upvotes: 1

Views: 4322

Answers (4)

Grigoris Kritopoulos
Grigoris Kritopoulos

Reputation: 424

Hello you can set your custom color like this

 charts.ColorUtil.fromDartColor(Colors.deepPurple) 

or

 charts.ColorUtil.fromDartColor(Color(0xff4EB200))

Upvotes: 2

Alberto L. Bonfiglio
Alberto L. Bonfiglio

Reputation: 1835

If you want different colors instead of shades you can use:

var palettes = charts.MaterialPalette.getOrderedPalettes(<number of palettes>);

var seriesColor = palettes.elementAt(i).shadeDefault; 

Upvotes: 0

Flomp
Flomp

Reputation: 524

I know this question is bit old, but I just had the same problem and found a solution.

    int numberOfColorsYouWant = 3;
    ...
    colorFn: (_, index){
      return charts.MaterialPalette.green.makeShades(numberOfColorsYouWant)[index];
    },

Upvotes: 7

Cristian Bregant
Cristian Bregant

Reputation: 1906

Not currently using it but just looked rapidly at the code and saw this:

colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
fillColorFn: (_, __) =>
        charts.MaterialPalette.blue.shadeDefault.lighter,

maybe you can change them changing this parameter.

This is the url where I found them : https://google.github.io/charts/flutter/example/bar_charts/stacked_fill_color

Upvotes: 3

Related Questions