Color from unique string lazarus / 39-Graphics ---------------------------------------------------------------------- Dibo · 2013-03-19 13:08 Hi, I'm using TChart . I dynamicaly create TLineSeries where count depend on list count. I would like that each series have different color depend on string item. For example: Code: [Select]Series1.SeriesColor := GetUniqueColor('table1') Series2.SeriesColor := GetUniqueColor('table2') Series3.SeriesColor := GetUniqueColor('table3') etc...Can't find any interesting function in Graphics unit Regards ---------------------------------------------------------------------- wp · 2013-03-19 13:39 There is no "official" function for that. But you can use a random color Code: [Select]uses LCLIntf;   Series1.SeriesColor := rgb(random(256), random(256), random(256));or use an array of predefined colors: Code: [Select]const   NUMCOLORS = 10;   SERIESCOLORS: array[0..NUMCOLORS-1] of TColor = (     clRed, clBlue, clOlive, //... etc    ); function GetSeriesColor(AIndex: integer): TColor; begin   Result := SERIESCOLORS[AIndex mod NUMCOLORS]; end; Series1.SeriesColor := GetSeriesColor(0); Series2.SeriesColor := GetSeriesColor(1); // etc. Note that in the last solution the colors are repeated after the predefined colors are used up. A variation would be to read the colors from an external file which gives the user the opportunity to change the colors: Code: [Select]var   SeriesColors: array of TColor; procedure ReadColorsFromFile(AFileName: string); var   List: TStringList; begin   List := TStringList.Create;   try     List.ReadFromFile(AFileName);     SetLength(SeriesColors, List.Count);     for i:=0 to List.Count-1 do       SeriesColors[i] := StringToColor(List[i]);   finally     List.Free;   end; It's your choice...