How to pick color palette for a pie-chart? [closed]

I solved it as follows:

  1. Choose a base color.
  2. Calculate its hue (baseHue).
  3. Create a color with the same saturation and luminosity, with its hue calculated as:
      hue = baseHue + ((240 / pieces) * piece % 240
    

In C#:

int n = 12;

Color baseColor = System.Drawing.ColorTranslator.FromHtml("#8A56E2");
double baseHue = (new HSLColor(baseColor)).Hue;

List<Color> colors = new List<Color>();
colors.Add(baseColor);

double step = (240.0 / (double)n);

for (int i = 1; i < n; ++i)
{
    HSLColor nextColor = new HSLColor(baseColor);
    nextColor.Hue = (baseHue + step * ((double)i)) % 240.0;
    colors.Add((Color)nextColor);
}

string colors = string.Join(",", colors.Select(e => e.Name.Substring(2)).ToArray());

I used the HSLColor class.

The Google Charts example that uses 12 pieces and a base color of #8A56E2:

Chart Example

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)