Search code examples
delphidelphi-7pie-chart

How can I change slice color of a Tdbchart runtime


I use a TDBChart in a Delphi7 project which gets its data from a TADOQuery.Chart. The type of TDBChart is Pie and the slices color is default colors (yellow, red, green).

I want to change the color of slices runtime. How can I do this?


Solution

  • I used TChart instead of TDbChart and wrote these codes for gettig value from TAdoQuery:

    with AdoQuery1 do
      begin
        i := 1;
        while not Eof do
          begin          
            chart1.Series[0].Add(fieldbyname('count').AsInteger,fieldbyname('statename').AsString,colors[i]);
            i := (i+1) mod 10;
            Next;
          end;
       end;
    

    when: colors is an array of colors we want.