Forum 

Forum AspNuke.it - Il tuo Portale OpenSource in ASP

Sondaggi con grafici a torte con le API di Google

Autore Messaggio
lucapuccetti

Utente
Utente
93 Discussioni



Profilo - lucapuccetti
14 marzo 2008 alle 00:01:28 Profilo - lucapuccettiInvia un messaggio privato Rispondi quotando
Sondaggi con grafici a torte con le API di Google

Usando le API di CHART di google è possibile rappresentare i risultati dei sondaggi con grafici a torte anziché a barre.

il mod

file polls-inc.asp


<%
' ************************************************************************
' * ASPNUKE: Free web portal in ASP *
' ************************************************************************
' * ASP-Nuke 2.0 Copyright (c) 2004 by Aspnuke.it Staff *
' * (staff@aspnuke.it) http://www.aspnuke.it *
' * *
' * Re-design by Enrico Musante (c) 2004 (emu@libero.it) *
' * Re-design by Frank Zalabard (c) 2004 (fsarzana@hotmail.com) *
' * *
' * ASP-Nuke 1.0, 1.1, 1.2 Copyright (c) 2002-2003 by Gaetan Bouveret *
' * (webmaster@asp-nuke.com) http://www.asp-nuke.com *
' * *
' * This program is free software. You can redistribute it and/or modify *
' * it under the terms of the GNU General Public License as published by *
' * the Free Software Foundation; either version 2 of the License, or *
' * (at your option) any later version. *
' * *
' ************************************************************************
%>
<%
' !!! Important !!! Don't remove this code
' Used to count any vote if valid
If Request.Form("poll") <> "" and Request.Cookies("poll_" & Request.Form("poll")) <> "OK" and Request.Form("result") <> "" Then
AddPollResult Request.Form("poll"), Request.Form("result")
End If

' Add a vote
' IN : iPollID (int) : poll's id (table polls, field pID)
' : iResultID (int) : choice's id (table pollsresults, field prID)
' OUT : -
Sub AddPollResult(iPollID, iResultID)
Dim oCn, rSQL

Set oCn = DBConnexion(DB_MAIN)

rSQL = "UPDATE pollsresults SET prHits=prHits+1 WHERE prPoll=" & iPollID & " AND prID=" & iResultID
DBExecute oCn, rSQL

Response.Cookies("poll_" & iPollID) = "OK"
Response.Cookies("poll_" & iPollID).Expires = Date+7

oCn.Close
Set oCn = Nothing
End Sub

' Display a poll
' IN : iID (int) : poll's id (table polls, field pID)
' : bIsInColumn (boolean) : change the display if poll is displayed in a column (small caps, displays a title (LANG_POLL))
' OUT : -
Sub DisplayPoll(iID, bIsInColumn)
Dim oCn, oRs, rSQL, nbVotes, MaxHits, iTdWidth, iLine, sPrefix, sPrefixSpan, sSuffixSpan, qString
dim stringauno, stringadue
Set oCn = DBConnexion(DB_MAIN)

nbVotes = 0
MaxHits = 0
sPrefix = ""
If bIsInColumn Then
sPrefixSpan = "<span class=""small"">"
sSuffixSpan = "</span>"
Else
sPrefixSpan = ""
sSuffixSpan = ""
End If

rSQL = "SELECT Sum(prHits), Max(prHits) FROM pollsresults WHERE prPoll=" & iID
Set oRs = DBRecordSet(oCn, rSQL)

nbVotes = oRs(0)
MaxHits = oRs(1)
If MaxHits <= 0 Then
MaxHits = 1
end if
oRs.Close
Set oRs = Nothing


rSQL = "SELECT prID, pColor, pTitle, prHits, prText FROM polls, pollsresults WHERE pID=prPoll AND pValid=1 AND pID=" & iID

Set oRs = DBRecordSet(oCn, rSQL)
If Not oRs.EOF Then
Response.Write " <a name=""poll_" & iID & """>" & vbCRLF
If bIsInColumn Then
CreateTopTable "poll_" & iID, GetTranslation("LANG_POLL")
sPrefix = "_"
Else
CreateTopTable "poll_" & iID, ""
End If
If Request.Cookies("poll_" & iID) = "OK" or Request.QueryString("results") <> "" Then
'Response.Write GLOBAL_SITE_SUBTABLE & vbCRLF
Response.Write "<table width=""100%"" cellspacing=""1"" cellpadding=""2"">"
Response.Write " <tr class=""tablelinemain"">" & vbCRLF
Response.Write " <td colspan=""2"" align=""center"">" & sPrefixSpan & Server.HTMLEncode(oRs("pTitle")) & sSuffixSpan & "</td>" & vbCRLF
Response.Write " </tr>" & vbCRLF
While Not oRs.EOF
iTdWidth = Round(100*(oRs("prHits")/MaxHits))
stringauno = iTdWidth &"," & stringauno
stringadue = Server.HTMLEncode(oRs("prText"))&" (" & oRs("prHits") & ")|" & stringadue

'Response.Write " <tr class=""tablelinemain"">" & vbCRLF
'Response.Write " <td>" & sPrefixSpan & Server.HTMLEncode(oRs("prText")) & " (" & oRs("prHits") & ")" & sSuffixSpan & "<br>" & vbCRLF
'Response.Write " <table width=""100%"" cellspacing=""2"" cellpadding=""2"">" & vbCRLF
'Response.Write " <tr><td width=""" & iTdWidth & "%"" bgcolor=""" & oRs("pColor") & """><img src=""" & GLOBAL_SITE_IMAGES_PATH & "space.gif"" height=""12"" border=""0""></td><td width=""" & 100-iTdWidth & "%""></td></tr>" & vbCRLF
'Response.Write " </table>" & vbCRLF
'Response.Write " </td>" & vbCRLF
'Response.Write " </tr>" & vbCRLF
oRs.MoveNext
WEnd

stringauno= LEFT(stringauno,(Len(stringauno)-1))
stringadue= LEFT(stringadue,(Len(stringadue)-1))
Response.Write " <tr class=""tablelinemain"">" & vbCRLF
Response.Write " <td align =""center"">" & vbCRLF
response.write"<img src=""http://chart.apis.google.com/chart?cht=p3&chd=t:" & stringauno & "&chs=450x150&chco=0000ff&chl=" & stringadue &""" alt="""" />" & vbCRLF

Response.Write " </td>" & vbCRLF
Response.Write " </tr>" & vbCRLF


Response.Write " <tr class=""tablelinemain"">" & vbCRLF
Response.Write " <td colspan=""2"" align=""center"">" & sPrefixSpan
If Request.QueryString("results") <> "" Then
Response.Write "<a href=""Java_Script:history.back()"">" & GetTranslation("LANG_POLL_VOTE") & "</a><br>"
End If
Response.Write GetTranslation("LANG_VOTES") & " : " & nbVotes & sSuffixSpan & "</td>" & vbCRLF
Response.Write " </tr>" & vbCRLF
Response.Write "</table>" & vbCRLF
Else
Response.Write "<_Script language=""Java_Script"" type=""text/Java_Script"">" & vbCRLF
Response.Write " var bCanVote_" & sPrefix & iID & " = false;" & vbCRLF
Response.Write " function votePoll_" & sPrefix & iID & "()" & vbCRLF
Response.Write " {" & vbCRLF
Response.Write " if (bCanVote_" & sPrefix & iID & ")" & vbCRLF
Response.Write " {" & vbCRLF
Response.Write " document.poll_" & sPrefix & iID & ".submit();" & vbCRLF
Response.Write " }" & vbCRLF
Response.Write " }" & vbCRLF
Response.Write " function voteOk_" & sPrefix & iID & "()" & vbCRLF
Response.Write " {" & vbCRLF
Response.Write " bCanVote_" & sPrefix & iID & " = true;" & vbCRLF
Response.Write " }" & vbCRLF
Response.Write "</_Script>" & vbCRLF
'Response.Write GLOBAL_SITE_SUBTABLE & vbCRLF
Response.Write "<table width=""100%"" cellspacing=""1"" cellpadding=""2"">"
Response.Write "<_form name=""poll_" & sPrefix & iID & """ method=""post"" action=""" & sUrlPage & """>" & vbCRLF
Response.Write "<input type=""hidden"" name=""poll"" value=""" & iID & """>" & vbCRLF
Response.Write " <tr class=""tablelinemain"">" & vbCRLF
Response.Write " <td colspan=""2"" align=""center"">" & sPrefixSpan & Server.HTMLEncode(oRs("pTitle")) & sSuffixSpan & "</td>" & vbCRLF
Response.Write " </tr>" & vbCRLF

iLine = 1
While Not oRs.EOF
Response.Write " <tr class=""tableline" & iLine & """>" & vbCRLF
Response.Write " <td width=""25""><input type=""radio"" name=""result"" onClick=""Java_Script:voteOk_" & sPrefix & iID & "()"" value=""" & oRs("prID") & """></td>" & vbCRLF
Response.Write " <td>" & sPrefixSpan & Server.HTMLEncode(oRs("prText")) & sSuffixSpan & "</td>" & vbCRLF
Response.Write " </tr>" & vbCRLF

iLine = 1 + ((iLine-1) XOR 1)
oRs.MoveNext
WEnd
Response.Write " <tr class=""tablelinemain"">" & vbCRLF
qString = Request.QueryString
If qString="" Then
qString = "?"
Else
qString = "?" & qString & "&"
End If
Response.Write " <td colspan=""2"" align=""center"">" & sPrefixSpan & "<a href=""Java_Script:votePoll_" & sPrefix & iID & "()"">" & GetTranslation("LANG_POLL_VOTE") & "</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href=""" & sURLPage & qString & "poll=" & iID & "&results=1"">" & GetTranslation("LANG_POLL_RESULTS") & "</a><br>" & GetTranslation("LANG_VOTES") & " : " & nbVotes & sSuffixSpan & "</td>" & vbCRLF
Response.Write " </tr>" & vbCRLF
Response.Write "</_form>" & vbCRLF
Response.Write "</table>" & vbCRLF
End If
CreateBottomTable ""
Else
CreateTable "NoPoll", GetTranslation("LANG_POLLS"), GetTranslation("LANG_EMPTY_SECTION"), ""
End If

oRs.Close
Set oRs = Nothing
oCn.Close
Set oCn = Nothing
End Sub

' Display the top polls (by Date)
' IN : iTop (int) : number of results wanted
' OUT : -
Sub DisplayTopPolls(iTop)
Dim oCn, oRs, rSQL, iLoop

Set oCn = DBConnexion(DB_MAIN)

If not( iTop <> "" and IsNumeric(iTop)) Then
iTop = 9999
End If
rSQL = "SELECT pID FROM polls, versions WHERE pDateBegin <= '" & DateTimeToString(Now()) & "' AND (pDateEnd >= '" & DateTimeToString(Now()) & "' OR pDateEnd < pDateBegin) AND pValid=1 AND pVersion=vID"
If sXMLVersion <> "" Then
rSQL = rSQL & " AND vCode='" & SQLEncrypt(sXMLVersion) & "'"
end if
rSQL = rSQL & " ORDER BY pDateBegin DESC, pDateEnd DESC"
Set oRs = DBRecordSet(oCn, rSQL)
If Not oRs.EOF Then
iLoop = 0
While Not oRs.EOF and iLoop < iTop
DisplayPoll oRs("pID"), False
oRs.MoveNext
iLoop = iLoop + 1
WEnd
Else
CreateTable "Poll", GetTranslation("LANG_POLL"), GetTranslation("LANG_EMPTY_SECTION"), ""
End If

oRs.Close
Set oRs = Nothing
oCn.Close
Set oCn = Nothing
End Sub

Sub DisplayLastPoll()
Dim oCn, oRs, rSQL

Set oCn = DBConnexion(DB_MAIN)

rSQL = "SELECT pID FROM polls, versions WHERE pDateBegin <= '" & DateTimeToString(Now()) & "' AND (pDateEnd >= '" & DateTimeToString(Now()) & "' OR pDateEnd < pDateBegin) AND pValid=1 AND pVersion=vID"
If sXMLVersion <> "" Then
rSQL = rSQL & " AND vCode='" & SQLEncrypt(sXMLVersion) & "'"
end if
rSQL = rSQL & " ORDER BY pDateBegin DESC, pDateEnd DESC"
Set oRs = DBRecordSet(oCn, rSQL)
If Not oRs.EOF Then
DisplayPoll oRs("pID"), True
end if
oRs.Close
Set oRs = Nothing
oCn.Close
Set oCn = Nothing
End Sub
%>


l'esempio

http://www.pillole.org/public/aspnuke/polls.asp?poll=3&results=1

saluti


A proposito per Veleno, si potrebbe fare in modo che quando si clicca su risultati invece di comparire tutti i risultati dei sondaggi attivi comparisse solo il risultato del sondaggio relativo a quello scelto ?


Luca
Angelo_bianconero

Principiante
Principiante
17 Discussioni



Profilo - Angelo_bianconero
14 marzo 2008 alle 07:06:09 Profilo - Angelo_bianconeroInvia un messaggio privato Rispondi quotando
io l'ho provato, ma ad inizio pagina, anzichè apparire il sondaggio (chi è + bello: tizio, caio, sempronio, etc,) appare questo:
<_Script language="Java_Script" type="text/Java_Script"> var bCanVote_4 = false; function votePoll_4() { if (bCanVote_4) { document.poll_4.submit(); } } function voteOk_4() { bCanVote_4 = true; } <_form name="poll_4" method="post" action="/polls.asp">
per il resto, a parte le tabelle + strette funziona! ciao
lucapuccetti

Utente
Utente
93 Discussioni



Profilo - lucapuccetti
14 marzo 2008 alle 15:58:56 Profilo - lucapuccettiInvia un messaggio privato Rispondi quotando


hai tolto tutti gli underscore che sono inseriti in automatico da aspnuke per depotenziare il codice ?

mi sembri che il Java_Script inizi con un underscore e che ci siano vari altri underscore da togliere.


il file "pulito" puoi scaricarlo da qui

http://www.consulto.net/files/polls-inc.zip

saluti

Luca

Log in

Login
Password
Memorizza i tuoi dati:

Cerca

 

Sostieni AspNuke

Un piccolo gesto per aiutarci a mantenere AspNuke.it online

Promo

MusicWebItalia.it
Video Testi Traduzioni Spot Colonne sonore Accordi e Spartiti gratis.

Visitatori

Visitatori Correnti : 102
Membri : 0 offline Anna

Iscritti

 Utenti: 18940
Ultimo iscritto : glauco
Lista iscritti
Messaggi privati: 3373 Commenti: 2210 Immagini: 39 Downloads: 144 Articoli: 49 Pagine: 101 Siti web: 558 Notizie: 180 Sondaggi: 11 Preferiti: 5685282 Post sui forum: 51195 Libro degli ospiti: 4 Eventi: 7

Versioni

Temi