Cita:
Empezado por nlsgarcia
jeremiselxi,
Revisa esta información:
Espero sea útil
Nelson.
|
Muchisisimas gracias
nlsgarcia.
Adjunto el código que me funcionó.
Primero debemos agregar un adoquery y renombrarlo como "table".
Hay que agregar un dbtchart y dando doble click agregar una serie.
Adjunto el código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, DbChart, Grids,
DBGrids, DB, ADODB, StdCtrls, DBClient;
type
TForm1 = class(TForm)
table: TADOQuery;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
tableACTIVIDADESREALIZADAS: TWideStringField;
tableTOTALES: TIntegerField;
DBChart1: TDBChart;
Series1: TPieSeries;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
const
GColor : Array[1..12] of TColor = (clGreen, clOlive, clNavy, clPurple, clTeal,
clGray, clSilver, clRed, clLime, clYellow,
clBlue, clFuchsia);
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
actividades : String;
totales : Integer;
i : Integer;
begin
if Assigned(Table) then
begin
i := 1;
with DBChart1 do
begin
Title.Text.Clear;
Title.Text.Add('Relación porcentual de las tareas rutinarias realizadas en el año'); Legend.Visible := true;
LeftAxis.Title.Caption := 'TOTALES'; LeftAxis.Title.Font.Color := clBlue;
BottomAxis.Title.Caption := 'ACTIVIDADES REALIZADAS'; BottomAxis.Title.Font.Color := clBlue;
end;
with Series1 do
begin
Clear;
Marks.Style := smsPercent;
with Table do
begin
Open;
while not eof do
begin
actividades := Table.FieldByName('ACTIVIDADES REALIZADAS').AsString;
totales := Table.FieldByName('TOTALES').AsInteger;
Add(totales, actividades, GColor[i]);
inc(i);
Next;
end;
end;
end;
end;
end;
Ahora solo tengo un solo problema y es como hacer para que el porcentaje del grafico este un poco desagrupado, ya que aparecen uno arriba de otro como muestra la imagen adjunta.
Alguien tiene alguna idea de como solucionarlo?.
Saludos y gracias