Graficas en Vfp 6.0
Tengo un ejemplo que baje en la red, lo que hace este ejemplo es llenar tablas temporales copiarlas a el excel y luego generar el grafico. Bueno modifique el codigo del ejemplo para llenara esas temporales con la informaciòn de mi sistema y lo hizo muy bien y tengo las temprales y el grafico en excel pero no puedo mostralo mediante una ole
mi correo es [email protected]
aqui esta el codigo......:
*-------------------------------------------------------
* Graficos.PRG
*-------------------------------------------------------
* Este programa genera aleatoriamente 2 tablas.
* (Ventas semanales por items y Ventas acumuladas anuales)
* y las copia con formato XLS para abrirlas con Excel y
* añadirles un gráfico mediante OLE
* AUTOR: Luis MarÃa Guayán
* EMAIL: [email protected]
* FECHA: 1999.10.10
*-------------------------------------------------------
SET DATE DMY
SET SAFETY OFF
*--- Crea las tablas que simulan las consultas
DO CreaArchivos
*--- Genera gráfico anual
DO GraficoAnual
*--- Genera gráfico semanal
DO GraficoSemanal
CLOSE TABLES ALL
RETURN
*-------------------------------------------------------
* PROCEDURE Crea_Arc
*-------------------------------------------------------
* Crea y llena las tablas de ejemplo y las copia
* como archivo tipo .XLS
*-------------------------------------------------------
PROCEDURE CreaArchivos
LOCAL lnI, ldFechaIni
*--- Inicializo la funcion RAND()
lnI = RAND(-1)
fec1 = ctod('27/12/1998')
ldFechaIni = fec1
*---- Creo tablas
CREATE TABLE Semana (Dia C(10), Item01 N(10,2), ;
Item02 N(10,2), Item03 N(10,2), Item04 N(10,2))
CREATE TABLE Anio (Mes C(10), TOTAL N(10,2))
*--- Cargo datos de los 7 dÃas y los 12 meses
FOR lnI = 1 TO 12
IF lnI <= 7
INSERT INTO Semana ;
(Dia, Item01, Item02, Item03, Item04) ;
VALUES (CDOW(ldFechaIni+lnI), RAND()*1000, ;
RAND()*1000, RAND()*1000, RAND()*1000 )
ENDIF
INSERT INTO Anio (Mes, TOTAL) ;
VALUES (CMONTH(GOMONTH(ldFechaIni,lnI)), RAND()*10000 )
ENDFOR
*--- Guardo como tipo XL5
SELECT Semana
COPY TO Semana TYPE XL5
SELECT Anio
COPY TO Anio TYPE XL5
RETURN
ENDPROC
*-------------------------------------------------------
* PROCEDURE Graf_Anu
*-------------------------------------------------------
* Creo un gráfico de Lineas en Excel
*-------------------------------------------------------
PROCEDURE GraficoAnual
LOCAL lnFil, lnCol, lcRango, lcPlanilla, lcHoja, loExcel
lnFil = RECCOUNT("Anio") + 1
lnCol = FCOUNT("Anio")
lcRango = "A1:" + CHR(64+lnCol) + ALLTRIM(STR(lnFil))
lcHoja = "Anio"
lcPlanilla = SYS(5) + CURDIR() + "Anio.xls"
*--- Creo objeto Excel
loExcel=CREATEOBJECT("Excel.application")
WITH loExcel.APPLICATION
.VISIBLE = .F. && oculto el trabajo en la aplicacion Excel
.workbooks.OPEN(lcPlanilla)
*---- Añado grafico de lÃneas
.Charts.ADD
.ActiveChart.ChartType = 65 && xlLineMarkers
.ActiveChart.SetSourceData(.Sheets(lcHoja).RANGE(lcRango), 2)
.ActiveChart.Location(1, "Grafico")
.ActiveChart.HasDataTable = .F.
*--- Estilo y ancho lÃnea
.ActiveChart.SeriesCollection(1).SELECT
WITH .SELECTION.BORDER
.Weight = 4 && xlThick
.LineStyle = 1 && xlContinuous
ENDWITH
*--- Titulo gráfico
.ActiveChart.HasTitle = .T.
.ActiveChart.ChartTitle.TEXT = "Ventas acumuladas anuales"
.ActiveChart.ChartTitle.SELECT
WITH .SELECTION.FONT
.NAME = "Arial"
.FontStyle = "Negrita"
.SIZE = 16
ENDWITH
*--- Leyenda
.ActiveChart.HasLegend = .T.
.ActiveChart.Legend.SELECT
.SELECTION.Position = -4160 && xlTop
*--- Ejes
WITH .ActiveChart
.Axes(1, 1).HasTitle = .T.
.Axes(1, 1).AxisTitle.TEXT = "Meses del año"
.Axes(2, 1).HasTitle = .T.
.Axes(2, 1).AxisTitle.TEXT = "Totales en U$S"
.Deselect
ENDWITH
*--- Grabo planilla y cierro
.VISIBLE = .F.
.ActiveWorkbook.SAVE
.workbooks.CLOSE
ENDWITH
RELE loExcel
RETURN
ENDPROC
*-------------------------------------------------------
* PROCEDURE Graf_Sem
*-------------------------------------------------------
* Gráfico de Barras Apiladas en Excel
*-------------------------------------------------------
PROCEDURE GraficoSemanal
LOCAL lnFil, lnCol, lcRango, lcPlanilla, lcHoja, loExcel
lnFil = RECCOUNT("Semana") + 1
lnCol = FCOUNT("Semana")
lcRango = "A1:" + CHR(64+lnCol) + ALLTRIM(STR(lnFil))
lcHoja = "Semana"
lcPlanilla = SYS(5) + CURDIR() + "Semana.xls"
*--- Creo objeto Excel
loExcel=CREATEOBJECT("Excel.application")
WITH loExcel.APPLICATION
.VISIBLE = .F. && oculto el trabajo en la aplicacion Excel
.workbooks.OPEN(lcPlanilla)
*---- Añado grafico barras apiladas
.Charts.ADD
.ActiveChart.ChartType = 52 && xlColumnStacked
.ActiveChart.SetSourceData(.Sheets(lcHoja).RANGE(lcRango), 2)
.ActiveChart.Location(1, "Grafico")
.ActiveChart.HasDataTable = .F.
*--- Titulo gráfico
.ActiveChart.HasTitle = .T.
.ActiveChart.ChartTitle.TEXT = "Ventas semanales por items"
.ActiveChart.ChartTitle.SELECT
WITH .SELECTION.FONT
.NAME = "Arial"
.FontStyle = "Negrita"
.SIZE = 16
ENDWITH
*--- Leyenda
.ActiveChart.HasLegend = .T.
.ActiveChart.Legend.SELECT
.SELECTION.Position = -4160 && xlTop
*--- Ejes
WITH .ActiveChart
.Axes(1, 1).HasTitle = .T.
.Axes(1, 1).AxisTitle.TEXT = "DÃas de la semana"
.Axes(2, 1).HasTitle = .T.
.Axes(2, 1).AxisTitle.TEXT = "Totales en U$S"
.Deselect
ENDWITH
*--- Grabo planilla y cierro
.VISIBLE = .F.
.ActiveWorkbook.SAVE
.workbooks.CLOSE
ENDWITH
RELE loExcel
RETURN
ENDPROC
*-------------------------------------------------------
* Fin archivo Graficos.PRG
*-------------------------------------------------------
*-------------------*
*OTRO EJEMPLO DE GRAFICOS
**------------------*
La parte principal del código de este ejemplo la tienes aquÃ:
Con un código relativamente parecido al anterior:
IF !USED('order_history')
RETURN .F.
ENDIF
SELECT order_history
=REQUERY()
LOCAL lnCount, lnRow
lnCount = _TALLY
lnRow = 1
ThisForm.Text1.Value = 0
WITH ThisForm.Olecontrol1.Object
.RowCount = 0
.RowLabelCount = 0
.RowCount = lnCount
.RowLabelCount = lnCount
SCAN
.Column = 1
.Row = lnRow
.RowLabel = ALLTRIM(order_id)
.Data = ord_total
lnRow = lnRow+1
ThisForm.Text1.Value = ord_total+ThisForm.Text1.Value
ENDSCAN
ENDWITH
WITH ThisForm.Olecontrol1
IF !.Visible
.Visible = .T.
ENDIF
ENDWITH
mi correo es [email protected]
aqui esta el codigo......:
*-------------------------------------------------------
* Graficos.PRG
*-------------------------------------------------------
* Este programa genera aleatoriamente 2 tablas.
* (Ventas semanales por items y Ventas acumuladas anuales)
* y las copia con formato XLS para abrirlas con Excel y
* añadirles un gráfico mediante OLE
* AUTOR: Luis MarÃa Guayán
* EMAIL: [email protected]
* FECHA: 1999.10.10
*-------------------------------------------------------
SET DATE DMY
SET SAFETY OFF
*--- Crea las tablas que simulan las consultas
DO CreaArchivos
*--- Genera gráfico anual
DO GraficoAnual
*--- Genera gráfico semanal
DO GraficoSemanal
CLOSE TABLES ALL
RETURN
*-------------------------------------------------------
* PROCEDURE Crea_Arc
*-------------------------------------------------------
* Crea y llena las tablas de ejemplo y las copia
* como archivo tipo .XLS
*-------------------------------------------------------
PROCEDURE CreaArchivos
LOCAL lnI, ldFechaIni
*--- Inicializo la funcion RAND()
lnI = RAND(-1)
fec1 = ctod('27/12/1998')
ldFechaIni = fec1
*---- Creo tablas
CREATE TABLE Semana (Dia C(10), Item01 N(10,2), ;
Item02 N(10,2), Item03 N(10,2), Item04 N(10,2))
CREATE TABLE Anio (Mes C(10), TOTAL N(10,2))
*--- Cargo datos de los 7 dÃas y los 12 meses
FOR lnI = 1 TO 12
IF lnI <= 7
INSERT INTO Semana ;
(Dia, Item01, Item02, Item03, Item04) ;
VALUES (CDOW(ldFechaIni+lnI), RAND()*1000, ;
RAND()*1000, RAND()*1000, RAND()*1000 )
ENDIF
INSERT INTO Anio (Mes, TOTAL) ;
VALUES (CMONTH(GOMONTH(ldFechaIni,lnI)), RAND()*10000 )
ENDFOR
*--- Guardo como tipo XL5
SELECT Semana
COPY TO Semana TYPE XL5
SELECT Anio
COPY TO Anio TYPE XL5
RETURN
ENDPROC
*-------------------------------------------------------
* PROCEDURE Graf_Anu
*-------------------------------------------------------
* Creo un gráfico de Lineas en Excel
*-------------------------------------------------------
PROCEDURE GraficoAnual
LOCAL lnFil, lnCol, lcRango, lcPlanilla, lcHoja, loExcel
lnFil = RECCOUNT("Anio") + 1
lnCol = FCOUNT("Anio")
lcRango = "A1:" + CHR(64+lnCol) + ALLTRIM(STR(lnFil))
lcHoja = "Anio"
lcPlanilla = SYS(5) + CURDIR() + "Anio.xls"
*--- Creo objeto Excel
loExcel=CREATEOBJECT("Excel.application")
WITH loExcel.APPLICATION
.VISIBLE = .F. && oculto el trabajo en la aplicacion Excel
.workbooks.OPEN(lcPlanilla)
*---- Añado grafico de lÃneas
.Charts.ADD
.ActiveChart.ChartType = 65 && xlLineMarkers
.ActiveChart.SetSourceData(.Sheets(lcHoja).RANGE(lcRango), 2)
.ActiveChart.Location(1, "Grafico")
.ActiveChart.HasDataTable = .F.
*--- Estilo y ancho lÃnea
.ActiveChart.SeriesCollection(1).SELECT
WITH .SELECTION.BORDER
.Weight = 4 && xlThick
.LineStyle = 1 && xlContinuous
ENDWITH
*--- Titulo gráfico
.ActiveChart.HasTitle = .T.
.ActiveChart.ChartTitle.TEXT = "Ventas acumuladas anuales"
.ActiveChart.ChartTitle.SELECT
WITH .SELECTION.FONT
.NAME = "Arial"
.FontStyle = "Negrita"
.SIZE = 16
ENDWITH
*--- Leyenda
.ActiveChart.HasLegend = .T.
.ActiveChart.Legend.SELECT
.SELECTION.Position = -4160 && xlTop
*--- Ejes
WITH .ActiveChart
.Axes(1, 1).HasTitle = .T.
.Axes(1, 1).AxisTitle.TEXT = "Meses del año"
.Axes(2, 1).HasTitle = .T.
.Axes(2, 1).AxisTitle.TEXT = "Totales en U$S"
.Deselect
ENDWITH
*--- Grabo planilla y cierro
.VISIBLE = .F.
.ActiveWorkbook.SAVE
.workbooks.CLOSE
ENDWITH
RELE loExcel
RETURN
ENDPROC
*-------------------------------------------------------
* PROCEDURE Graf_Sem
*-------------------------------------------------------
* Gráfico de Barras Apiladas en Excel
*-------------------------------------------------------
PROCEDURE GraficoSemanal
LOCAL lnFil, lnCol, lcRango, lcPlanilla, lcHoja, loExcel
lnFil = RECCOUNT("Semana") + 1
lnCol = FCOUNT("Semana")
lcRango = "A1:" + CHR(64+lnCol) + ALLTRIM(STR(lnFil))
lcHoja = "Semana"
lcPlanilla = SYS(5) + CURDIR() + "Semana.xls"
*--- Creo objeto Excel
loExcel=CREATEOBJECT("Excel.application")
WITH loExcel.APPLICATION
.VISIBLE = .F. && oculto el trabajo en la aplicacion Excel
.workbooks.OPEN(lcPlanilla)
*---- Añado grafico barras apiladas
.Charts.ADD
.ActiveChart.ChartType = 52 && xlColumnStacked
.ActiveChart.SetSourceData(.Sheets(lcHoja).RANGE(lcRango), 2)
.ActiveChart.Location(1, "Grafico")
.ActiveChart.HasDataTable = .F.
*--- Titulo gráfico
.ActiveChart.HasTitle = .T.
.ActiveChart.ChartTitle.TEXT = "Ventas semanales por items"
.ActiveChart.ChartTitle.SELECT
WITH .SELECTION.FONT
.NAME = "Arial"
.FontStyle = "Negrita"
.SIZE = 16
ENDWITH
*--- Leyenda
.ActiveChart.HasLegend = .T.
.ActiveChart.Legend.SELECT
.SELECTION.Position = -4160 && xlTop
*--- Ejes
WITH .ActiveChart
.Axes(1, 1).HasTitle = .T.
.Axes(1, 1).AxisTitle.TEXT = "DÃas de la semana"
.Axes(2, 1).HasTitle = .T.
.Axes(2, 1).AxisTitle.TEXT = "Totales en U$S"
.Deselect
ENDWITH
*--- Grabo planilla y cierro
.VISIBLE = .F.
.ActiveWorkbook.SAVE
.workbooks.CLOSE
ENDWITH
RELE loExcel
RETURN
ENDPROC
*-------------------------------------------------------
* Fin archivo Graficos.PRG
*-------------------------------------------------------
*-------------------*
*OTRO EJEMPLO DE GRAFICOS
**------------------*
La parte principal del código de este ejemplo la tienes aquÃ:
Con un código relativamente parecido al anterior:
IF !USED('order_history')
RETURN .F.
ENDIF
SELECT order_history
=REQUERY()
LOCAL lnCount, lnRow
lnCount = _TALLY
lnRow = 1
ThisForm.Text1.Value = 0
WITH ThisForm.Olecontrol1.Object
.RowCount = 0
.RowLabelCount = 0
.RowCount = lnCount
.RowLabelCount = lnCount
SCAN
.Column = 1
.Row = lnRow
.RowLabel = ALLTRIM(order_id)
.Data = ord_total
lnRow = lnRow+1
ThisForm.Text1.Value = ord_total+ThisForm.Text1.Value
ENDSCAN
ENDWITH
WITH ThisForm.Olecontrol1
IF !.Visible
.Visible = .T.
ENDIF
ENDWITH
