Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Office Web Components to create a chart.

COM and Automation

How to use Office Web Components to create a chart.

by  Mike Gagnon  Posted    (Edited  )
The following creates a Jpeg picture of a chart you can use in your application on forms, in reports etc... This example sends the chart to the Internet Explorer.
This requires Microsoft's Office Web Components. (http://office.microsoft.com/downloads/2002/owc10.aspx).

Code:
Local i
Store 0 To i
Dimension laLabels[3]
Dimension laData[3]
Dimension laData2[3]
Create Cursor final (pic m)
Create Cursor sales (Name c(20),total1 N(10),total2 N(10))
Insert Into sales (Name,total1,total2) Values ("Total sales Mike",1000,2000)
Insert Into sales (Name,total1,total2) Values ("Total sales Frank",2550,2500)
Insert Into sales (Name,total1,total2) Values ("Total sales Fred",1292,500)
Go Top
Do While !Eof()
    i = i +1
    laLabels[i]=sales.Name
    laData[i]=sales.total1
    laData2[i]=sales.total2
    Select sales
    Skip
Enddo
loChartSpace = Createobject("OWC10.ChartSpace")
oConst = loChartSpace.Constants
loGraph = loChartSpace.Charts.Add()
loGraph.Type =47
loGraph.HasLegend = .T.
loGraph.PlotArea.Interior.Color="Pink"
loChartSpace.HasChartSpaceTitle = .T.
loChartSpace.ChartSpaceTitle.Caption = "Monthly Sales for My Company Inc."
loChartSpace.ChartSpaceTitle.Font.Bold = .T.
loGraph.SeriesCollection.Add()
loGraph.SeriesCollection(0).Caption = "Sales of widgets #1"
loGraph.SeriesCollection(0).SetData(oConst.chDimCategories, oConst.chDataLiteral, @laLabels)
loGraph.SeriesCollection(0).SetData(oConst.chDimValues, oConst.chDataLiteral, @laData)
loGraph.SeriesCollection.Add()
loGraph.SeriesCollection(1).Caption = "Sales of widgets #2"
loGraph.SeriesCollection(1).SetData(oConst.chDimValues, oConst.chDataLiteral, @laData2)
lcFile = Sys(2023) + "\" + Sys(2015) + ".jpg"
loChartSpace.ExportPicture(lcFile, "jpg",800,600)
oBrowser = CREATEOBJECT("internetexplorer.application")
oBrowser.navigate(lcFile)
oBrowser.visible = .t.
[sub]
P.S. Some of this code was partially written by Rick Strahl.[/sub]
Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top