Вы находитесь на странице: 1из 13

<!-- #include file = "../../Include/MB_Connection.

asp" -->
<%
Function ExportChartToGIF(objCSpace, strAbsFilePath, strRelFilePath)
'*************************************************
***************************
'ExportChartToGIF generates the chart in a .GIF file format
'*************************************************
***************************
Dim strFileName
strFileName = "CPA_Graph.gif"
objCSpace.ExportPicture strAbsFilePath & "\" & strFileName,
"gif", 900, 500
ExportChartToGIF = strRelFilePath & "/" & strFileName
End Function
Sub CleanUpGIF(GIFpath)
'*************************************************
***************************
'CleanUpGIF removes any generated .GIF files that are over 1
minute old.
'This will be used if we need to generate different files.
'*************************************************
***************************
Dim objFS
'file system object
Dim objFolder 'folder object
Dim gif
'loop holder for each file
'Create file system object and get path to files
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(GIFpath)
'Loop through folder and delete old files
For Each gif In objFolder.Files
If instr(gif.Name, ".gif") > 0 And DateDiff("n",
gif.DateLastModified, now) > 1 Then
objFS.DeleteFile GIFpath & "\" & gif.Name, True
End If
Next
'clean up objects
Set objFolder = Nothing
Set objFS = Nothing
End Sub
'Get Today's Date
Dim dteToday
dteToday = Date()
'Get the date of the last report worked (last sunday)

Dim intNumDaysBack, dteLastReport


intNumDaysBack = WeekDay(dteToday) - 1
' current
dteLastReport = DateAdd("d", -intNumDaysBack, dteToday)
'Get the date one year before the last report worked (last sunday - 1
year)
Dim dteOneYearBack
intNumDaysBack = WeekDay(dteToday) + 364
' current
dteOneYearBack = DateAdd("d", -intNumDaysBack, dteToday)
'Get Connection
Dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = GetCnString("DASHBOARD")
oConn.Open strConn
'Get Recordset
Dim rsHistory, strSQL
Set rsHistory = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM DB_CPA_History_Client AS DC"
strSQL = strSQL & " WHERE Client = 'AP1'"
strSQL = strSQL & " AND [Date] BETWEEN '" & dteOneYearBack & "' AND '" &
dteLastReport & "'"
strSQL = strSQL & " ORDER BY [Date]"
With rsHistory
.ActiveConnection = oConn
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open strSQL
End With
Dim strChartAbsPath
Dim strChartRelPath
Dim
Dim
Dim
Dim
Dim
Dim

objChartSpace
objChart
c
objSeries
objAxis
objFont

'Get the relative and absolute path names for the GIF folder
strChartAbsPath = Server.MapPath("/medbill/dashboard/CPA/temp")
strChartRelPath = "temp"
'Create ChartSpace
Set objChartSpace = Server.CreateObject("OWC11.ChartSpace")
With objChartSpace
Set c = .Constants
Set .DataSource = rsHistory

.HasChartSpaceTitle = True
.ChartSpaceTitle.Caption = "CPA History"
.ChartSpaceTitle.Font.Bold = True
.ChartSpaceTitle.Font.Size = 16
.HasChartSpaceLegend = True
.ChartSpaceLegend.Position = c.chLegendPositionRight
.Border.Color = "Black"
.Border.Weight = c.owcLineWeightThick
.DisplayFieldButtons = False
.DisplayFieldList = False
.SetData c.chDimCategories, 0, "Date"
.SetData c.chDimValues, 0, "Charges"
End With
'Create Chart in .GIF File Format and return file name
Dim strChartFile
strChartFile = ExportChartToGIF(objChartSpace, strChartAbsPath,
strChartRelPath)
'Clean up objects
Set objChartSpace
Set objChartLegend
Set objChart
Set c
Set objSeries
Set objAxis
Set objFont

= Nothing
= Nothing
= Nothing
= Nothing
= Nothing
= Nothing
= Nothing

DestroyObject(rsHistory)
DestroyObject(oConn)
%>
<html>
<head>

<title>Chart Example</title>

</head>
<body>
<p>
</p>
</body>

</html>

<img src="<%=strChartFile%>" />

<!-- #include file = "../../Include/MB_Connection.asp" -->


<%
Function ExportChartToGIF(objCSpace, strAbsFilePath, strRelFilePath)
'*************************************************
***************************
'ExportChartToGIF generates the chart in a .GIF file format
'*************************************************
***************************
Dim strFileName
strFileName = "CPA_Graph.gif"
objCSpace.ExportPicture strAbsFilePath & "\" & strFileName,
"gif", 900, 500
ExportChartToGIF = strRelFilePath & "/" & strFileName
End Function
Sub CleanUpGIF(GIFpath)
'*************************************************
***************************
'CleanUpGIF removes any generated .GIF files that are over 1
minute old.
'This will be used if we need to generate different files.
'*************************************************
***************************
Dim objFS
'file system object
Dim objFolder 'folder object
Dim gif
'loop holder for each file
'Create file system object and get path to files
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(GIFpath)
'Loop through folder and delete old files
For Each gif In objFolder.Files
If instr(gif.Name, ".gif") > 0 And DateDiff("n",
gif.DateLastModified, now) > 1 Then
objFS.DeleteFile GIFpath & "\" & gif.Name, True
End If
Next
'clean up objects
Set objFolder = Nothing
Set objFS = Nothing
End Sub
'Get Today's Date
Dim dteToday
dteToday = Date()
'Get the date of the last report worked (last sunday)

Dim intNumDaysBack, dteLastReport


intNumDaysBack = WeekDay(dteToday) - 1
' current
dteLastReport = DateAdd("d", -intNumDaysBack, dteToday)
'Get the date one year before the last report worked (last sunday - 1
year)
Dim dteOneYearBack
intNumDaysBack = WeekDay(dteToday) + 364
' current
dteOneYearBack = DateAdd("d", -intNumDaysBack, dteToday)
'Get Connection
Dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = GetCnString("DASHBOARD")
oConn.Open strConn
'Get Recordset
Dim rsHistory, strSQL
Set rsHistory = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM DB_CPA_History_Client AS DC"
strSQL = strSQL & " WHERE Client = 'AP1'"
strSQL = strSQL & " AND [Date] BETWEEN '" & dteOneYearBack & "' AND '" &
dteLastReport & "'"
strSQL = strSQL & " ORDER BY [Date]"
With rsHistory
.ActiveConnection = oConn
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open strSQL
End With
Dim strChartAbsPath
Dim strChartRelPath
Dim
Dim
Dim
Dim
Dim
Dim

objChartSpace
objChart
c
objSeries
objAxis
objFont

'Get the relative and absolute path names for the GIF folder
strChartAbsPath = Server.MapPath("/medbill/dashboard/CPA/temp")
strChartRelPath = "temp"
'Create ChartSpace
Set objChartSpace = Server.CreateObject("OWC11.ChartSpace")
With objChartSpace
Set c = .Constants
Set .DataSource = rsHistory

.HasChartSpaceTitle = True
.ChartSpaceTitle.Caption = "CPA History"
.ChartSpaceTitle.Font.Bold = True
.ChartSpaceTitle.Font.Size = 16
.HasChartSpaceLegend = True
.ChartSpaceLegend.Position = c.chLegendPositionRight
.Border.Color = "Black"
.Border.Weight = c.owcLineWeightThick
.DisplayFieldButtons = False
.DisplayFieldList = False
'commented out. I am using the charts property now...
'.SetData c.chDimCategories, 0, "Date"
'.SetData c.chDimValues, 0, "Charges"
.Charts(0).Type = c.chChartTypeLineMarkers
.Charts(0).SeriesCollection(0).Caption = "Charges"
.Charts(0).SeriesCollection(0).SetData c.chDimCategories, 0,
"Date"

.Charts(0).SeriesCollection(0).SetData c.chDimValues, 0,
"Charges"
End With
......rest of code is the cleanup stuff......

Corrected Code:
Function ExportChartToGIF(objCSpace, strAbsFilePath, strRelFilePath)
'*************************************************
***************************
'ExportChartToGIF generates the chart in a .GIF file format
'*************************************************
***************************
Dim strFileName
strFileName = "CPA_Graph.gif"
objCSpace.ExportPicture strAbsFilePath & "\" & strFileName,
"gif", 900, 500
ExportChartToGIF = strRelFilePath & "/" & strFileName
End Function
Sub CreateXML()
'Get Connection
Dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = GetCnString("DASHBOARD")
oConn.Mode = 3
oConn.Open strConn
'Get XML Stream
Dim adStream
Set adStream = Server.CreateObject("ADODB.Stream")
'Get Recordset
Dim rsHistory, strSQL
Set rsHistory = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM DB_CPA_History_Client AS DC"
strSQL = strSQL & " WHERE Client = 'AP1' AND [Date] BETWEEN '" &
dteOneYearBack & "' AND '" & dteLastReport & "' ORDER BY [Date] ASC"
'open recordset
With rsHistory
.CursorLocation = adUseClient
.Open strSQL, oConn, adOpenStatic, adLockReadOnly,
adCmdText
.Save adStream, adPersistXML
.Close
End With
'stream recordset to XML file
With adStream
.SaveToFile strXMLPath, adSaveCreateOverWrite
.Close
End With
'clean up
Set adStream = Nothing

Set rsHistory = Nothing


Set oConn = Nothing
Response.Write strSQL
End Sub
'*************************************************
*************************************
'MAIN
'*************************************************
*************************************
'Get Today's Date
Dim dteToday
dteToday = Date()
'Get the date of the last report worked (last sunday --> date from)
Dim intNumDaysBack, dteLastReport
intNumDaysBack = WeekDay(dteToday) - 1
' current
dteLastReport = DateAdd("d", -intNumDaysBack, dteToday)
'Get the date one year before the last report worked (last sunday - 1
year --> date to)
Dim dteOneYearBack
intNumDaysBack = WeekDay(dteToday) + 364
' current
dteOneYearBack = DateAdd("d", -intNumDaysBack, dteToday)
'Get the relative and absolute path names for the GIF folder
strChartAbsPath = Server.MapPath("/medbill/dashboard/CPA/temp")
strChartRelPath = "temp"
Dim strXMLPath
strXMLPath = mypath
'Create XML file
Call CreateXML()
'Set up chart
dim stCon
stCon = "Provider=MSPersist;"
Dim objChartSpace, c
Set objChartSpace = Server.CreateObject("OWC11.ChartSpace")
Set c = objChartSpace.Constants
'Setup the Chart Space.
With objChartSpace
.Clear()
.ConnectionString = stCon
.CommandText = strXMLPath
.Border.Color = RGB(153, 204, 204)
.Interior.Color = RGB(153, 204, 204)
.DisplayToolbar = False

.DisplayPropertyToolbox = False
.DisplayFieldList = True
.DisplayFieldButtons = False
.AllowUISelection = False
With .DropZones(chDropZoneFilter)
.ButtonInterior.Color = vbWhite
.ButtonFont.Color = vbBlue
End With
With .DropZones(chDropZoneCategories)
.ButtonInterior.Color = vbWhite
.ButtonFont.Color = vbBlue
End With
End With
With objChartSpace.Charts(0)
.Type = c.chChartTypeLineMarkers
.HasTitle = True
.Interior.SetTwoColorGradient c.chGradientHorizontal,
c.chGradientVariantCenter, RGB(255, 255, 204), RGB(204, 204, 204)
.HasLegend = True
.Legend.Position = c.chLegendPositionRight
With .SeriesCollection(0)
.Line.Color
= "Black"
.Marker.Style = c.chMarkerStyleCircle
.Interior.Color = "Blue"
.Caption
= "Charges"
.SetData c.chDimCategories, 0, "Date"
.SetData c.chDimValues, c.chDataBound, "Charges"
End With
.SeriesCollection.Add()
With .SeriesCollection(1)
.Line.Color
= "Red"
.Marker.Style = c.chMarkerStyleCircle
.Interior.Color = "Yellow"
.Caption
= "Payments"
.SetData c.chDimCategories, 0, "Date"
.SetData .chDimValues, .chDataBound, "Payments"
End With
With .Title
.Caption = "CPA History"

.Font.Name = "Verdana"
.Font.Size = 10
.Font.Bold = True
.Font.Color = RGB(0, 51, 153)
End With
With .Axes(0)
.HasTitle = True
With .Title
.Caption = "Report Date"
.Font.Name = "Verdana"
.Font.Bold = True
.Font.Size = 8
.Font.Color = RGB(0, 51, 153)
End With
.Orientation = c.chLabelOrientationDownward
End With
With .Axes(1)
.HasTitle = True
With .Title
.Caption = "Charges"
.Font.Name = "Verdana"
.Font.Bold = True
.Font.Size = 8
.Font.Color = RGB(0, 51, 153)
End With
.NumberFormat = "Currency"
End With
End With
'Create Chart in .GIF File Format and return file name
strChartFile = ExportChartToGIF(objChartSpace, strChartAbsPath,
strChartRelPath)
'clean up
Set objChartSpace = Nothing
%>

<html>
<head>

<title>CPA Graph</title>

</head>
<body>
<p>
</p>

<img src="<%=strChartFile%>" />

</body>
</html>

'Setup the Chart Space.


With objChartSpace
.Clear()
.ConnectionString = stCon
.CommandText = strXMLPath
.Border.Color = RGB(153, 204, 204)
.Interior.Color = RGB(153, 204, 204)
.DisplayToolbar = False
.DisplayPropertyToolbox = False
.DisplayFieldList = True
.DisplayFieldButtons = False
.AllowUISelection = False
.SetData c.chDimCategories, 0, "Date"
.SetData c.chDimValues, c.chDataBound, "Charges"
With .DropZones(chDropZoneFilter)
.ButtonInterior.Color = vbWhite
.ButtonFont.Color = vbBlue
End With
With .DropZones(chDropZoneCategories)
.ButtonInterior.Color = vbWhite
.ButtonFont.Color = vbBlue
End With

End With
With objChartSpace
.Clear()
.ConnectionString = stCon
.CommandText = strXMLPath
.Border.Color = RGB(153, 204, 204)
.Interior.Color = RGB(153, 204, 204)
.DisplayToolbar = False
.DisplayPropertyToolbox = False
.DisplayFieldList = True
.DisplayFieldButtons = False
.AllowUISelection = False
.PlotAllAggregates = c.chPlotAggregatesSeries
.SetData c.chDimCategories, c.chDataBound, "Date"
.SetData c.chDimValues, c.chDataBound, Array("Charges", "Payments")
With .DropZones(chDropZoneFilter)
.ButtonInterior.Color = vbWhite
.ButtonFont.Color = vbBlue
End With

With .DropZones(chDropZoneCategories)
.ButtonInterior.Color = vbWhite
.ButtonFont.Color = vbBlue
End With
End With
With the chPlotAggregatesSeries property of the constants object, you can graph
multiple series and reference them later with the SeriesCollection object via index
like so:
Code:

With .SeriesCollection(0)
.Line.Color = "Black"
.Marker.Style = c.chMarkerStyleCircle
.Interior.Color = "Blue"
.Caption = "Charges"
End With
With .SeriesCollection(1)
.Line.Color = "Black"
.Marker.Style = c.chMarkerStyleCircle
.Interior.Color = "Yellow"
.Caption = "Payments"
End With

Вам также может понравиться