-
Notifications
You must be signed in to change notification settings - Fork 1
/
GoogleChart.hta
executable file
·115 lines (88 loc) · 3 KB
/
GoogleChart.hta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="en">
<head>
<title>Using a Google Chart</title>
<HTA:APPLICATION
APPLICATIONNAME = "Google Chart"
ICON = "599CD.ico"
/>
<script language="vbscript">
' Connection String
Dim sConnect
'Commands
Dim objCmdPC 'Pie Chart
'RecordSets
Dim objRSPC
'Initialize Connection String to connect to an MS Access Database
sConnect = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=PCResale.accdb;Persist Security Info=False"
Sub CreateChart()
'Create a command object to execute Advancded SQL Statements
Set objCmdPC = CreateObject("ADODB.Command")
objCmdPC.ActiveConnection = sConnect 'Connect to database
' Total Number Customers in a Company
objCmdPC.CommandText = "SELECT CustomerT.CompanyName, Count(CustomerT.CompanyName) AS CountOfCompanyName FROM CustomerT GROUP BY CustomerT.CompanyName;"
' Create the actual recordset to be used in this script
' and retrieve or display information from database
Set objRSPC = CreateObject("ADODB.Recordset")
Set objRSPC = objCmdPC.Execute
Dim strPC
Dim chartTitle
Dim chartValues
Dim chartLabels
Dim chartColours
Dim chtType
Dim n
For n = 0 to Document.Charts.chtType.length - 1
If Document.Charts.chtType(n).checked Then
chtType = Document.Charts.chtType(n).Value
End If
Next
While Not objRSPC.EOF
chartLabels = chartLabels & objRSPC("CompanyName") & " (" & objRSPC("CountOfCompanyName") & ")" & "|"
chartValues = chartValues & objRSPC("CountOfCompanyName") & ","
objRSPC.MoveNext
Wend
chartLabels = Left(chartLabels, len(chartLabels)-1)
chartValues = Left(chartValues, len(chartValues)-1)
chartTitle = "Number of Customers in a Company"
'https://developers.google.com/chart/image/docs/chart_params#gcharts_chs
'chtt=<chart_title>
'chts=<color>,<font_size>,<opt_alignment>
'chs=<width>x<height>
'chf=<fill_type>,s,<color>
'cht=<chart_type>
'chd=t:s,e,r,i,e,s,1|s,e,r,i,e,s,2|... OR s:series1,series2,... OR e:series1,series2,...
'chl=<label>|...
strPC = "<img src='http://chart.apis.google.com/chart?" &_
"chtt=" & chartTitle & "&" &_
"chts=000000,12&" &_
"chs=450x150&" &_
"chf=bg,s,ffffff&" &_
"cht=" & chtType & "&" &_
"chd=t:" & chartValues & "&" &_
"chl=" & chartLabels & "&" &_
"chco=FFCC00,33CC00,3333FF,CC0000' " &_
"alt='" & chartTitle & "'/>"
'msgbox strPC
document.Charts.source.value = strPC
myContent.innerHTML = strPC
'Clean Up and Close
objRSPC.Close
Set objRSPC = Nothing
End Sub
</script>
</head>
<body>
<h1>Google Charts</h1>
<form name="Charts" method="post" action="GoogleChart.hta">
<input type="button" value="Chart" OnClick="CreateChart()">
<input type="radio" name="chtType" value="p"> Flat
<input type="radio" name="chtType" value="p3" checked="checked"> Angled
<br />
<input type="text" name="source" id="source" size="100">
</form>
<h2>Results</h2>
<div id="myContent">
</div>
</body>
</html>