14 marzo 2008 alle 00:01:28 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
' 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
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 %>
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
17 Discussioni
14 marzo 2008 alle 07:06:09 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
93 Discussioni
14 marzo 2008 alle 15:58:56
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.