Ver Mensaje Individual
  #5  
Antiguo 14-03-2017
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Un ejemplo básico:
Código SQL [-]
/* Tabla vendedores */
CREATE TABLE VENDORS (
    ID      INTEGER,
    NOMBRE  VARCHAR(20)
);

/* Tabla ventas */
CREATE TABLE VENTAS (
    ID       INTEGER,
    FECHA    DATE,
    VEND_ID  INTEGER,
    MONTO    NUMERIC(18,3)
);

Datos (VENDORS)
Código:
ID	NOMBRE
1	JUAN
2	PEDRO
3	ANA
4	MARIO
5	BEATRIZ
Datos (VENTAS)
Código:
ID    FECHA	     VEND_ID	MONTO
1     01.03.2017     1   	100
2     01.03.2017     1	         50
3     01.03.2017     2	        105
3     01.03.2017     3	        109
4     01.03.2017     4	         27
5     01.03.2017     5	        203

Delphi:
Código Delphi [-]
...
implementation

uses Series;

procedure TForm1.ShowChart( const Fecha: TDate );
var
  i : Integer;
  se: TBarSeries;
begin
  tuQuery.Close;
  tuQuery.SQL.Clear;
  tuQuery.SQL.Add( 'SELECT VD.NOMBRE AS NOMBRE, SUM(VT.MONTO) AS MONTO' );
  tuQuery.SQL.Add( 'FROM VENTAS VT JOIN VENDORS VD ON VT.VEND_ID = VD.ID' );
  tuQuery.SQL.Add( 'WHERE VT.FECHA = :FECHA' );
  tuQuery.SQL.Add( 'GROUP BY VD.NOMBRE' );
  tuQuery.ParamByName( 'FECHA' ).AsDate := Fecha;
  tuQuery.Open;

  for i := Chart1.SeriesCount-1 downto 0 do
    Chart1.Series[i].Free;

  while not tuQuery.Eof do
  begin
    se := TBarSeries.Create( Self );
    se.ShowInLegend := false;
    se.Add( tuQuery.FieldByName( 'MONTO' ).AsFloat,
            tuQuery.FieldByName( 'NOMBRE' ).AsString );
    Chart1.AddSeries( se );
    tuQuery.Next;
  end;
end;


// Ejemplo de llamada
procedure TForm1.btnShowClick( Sender: TObject );
begin
  ShowChart( StrToDate( '01/03/2017' ) ); 
end;

Salida:


Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita