Perhaps like some of you, I find that the Fox language is so rich with string handling tools that I often use if for a lot of chores. One of these includes generating static reports in the form of HTML pages.
But many of my reports includes lots of numbers and time components, so a graph or two on each report would greatly enhance readability and usefulness. But I couldn't find a tool that would allow me to create a graph based on the data I had collected and generate an image file such as a GIF.
I posted the question [thread253-53244] in the Web Sie Designers forum asking for tool recommendations for creating a graph on the fly. I received some good answers, but none that exactly fit the problem. I eventually stumbled upon it: Office Web Components. OWC may be installed on your machine, as it comes with a variety of Microsoft products.
Below is my code for creating a basic graph using a cursor/table:
[tt]* -- makes a chart using the currently open table/cursor
* -- the first column should be the X-axis labels,
* -- and the rest of the columns should be the Y-axis values
Parameters cOutFile, cCaption
if empty(alias())
wait window "No table/alias open in current work area" timeout 200
return
endif
* -- put the contents into an array
dimension aLabels(reccount())
dimension aValues(reccount())
go top
for i = 1 to reccount()
aLabels(i) = alltrim(evaluate(field(1)))
aValues(i) = evaluate((field(2)))
skip
endfor
if empty(cCaption)
cCaption = "Graph"
endif
if empty(cOutFile)
cOutFile = "chart.gif"
endif
oChart = CreateObject("OWC.Chart"
oChart.Charts.Add
oChart.Charts(0).Type = oChart.Constants.chChartTypeColumnClustered
oChart.Charts(0).SeriesCollection.Add
oChart.Charts(0).SeriesCollection(0).Caption = cCaption
oChart.Charts(0).SeriesCollection(0).SetData(oChart.Constants.chDimCategories, oChart.Constants.chDataLiteral, @aLabels)
oChart.Charts(0).SeriesCollection(0).SetData(oChart.Constants.chDimValues, oChart.Constants.chDataLiteral, @aValues)
oChart.Charts(0).HasLegend = .F.
oChart.Charts(0).HasTitle = .T.
oChart.ExportPicture(cOutFile, "gif", 500, 300)
release oChart
[/tt]
Robert Bradley
Do you have too much money? Visit
But many of my reports includes lots of numbers and time components, so a graph or two on each report would greatly enhance readability and usefulness. But I couldn't find a tool that would allow me to create a graph based on the data I had collected and generate an image file such as a GIF.
I posted the question [thread253-53244] in the Web Sie Designers forum asking for tool recommendations for creating a graph on the fly. I received some good answers, but none that exactly fit the problem. I eventually stumbled upon it: Office Web Components. OWC may be installed on your machine, as it comes with a variety of Microsoft products.
Below is my code for creating a basic graph using a cursor/table:
[tt]* -- makes a chart using the currently open table/cursor
* -- the first column should be the X-axis labels,
* -- and the rest of the columns should be the Y-axis values
Parameters cOutFile, cCaption
if empty(alias())
wait window "No table/alias open in current work area" timeout 200
return
endif
* -- put the contents into an array
dimension aLabels(reccount())
dimension aValues(reccount())
go top
for i = 1 to reccount()
aLabels(i) = alltrim(evaluate(field(1)))
aValues(i) = evaluate((field(2)))
skip
endfor
if empty(cCaption)
cCaption = "Graph"
endif
if empty(cOutFile)
cOutFile = "chart.gif"
endif
oChart = CreateObject("OWC.Chart"
oChart.Charts.Add
oChart.Charts(0).Type = oChart.Constants.chChartTypeColumnClustered
oChart.Charts(0).SeriesCollection.Add
oChart.Charts(0).SeriesCollection(0).Caption = cCaption
oChart.Charts(0).SeriesCollection(0).SetData(oChart.Constants.chDimCategories, oChart.Constants.chDataLiteral, @aLabels)
oChart.Charts(0).SeriesCollection(0).SetData(oChart.Constants.chDimValues, oChart.Constants.chDataLiteral, @aValues)
oChart.Charts(0).HasLegend = .F.
oChart.Charts(0).HasTitle = .T.
oChart.ExportPicture(cOutFile, "gif", 500, 300)
release oChart
[/tt]
Robert Bradley
Do you have too much money? Visit