PDA

View Full Version : Javascript to display graph on your website


cruelio
12-26-2003, 07:42 PM
be careful this works for your visitors and not just you

i whipped this up for my website, so my visitors can see the graph, and click on it for more details. copy and paste the code below, make sure to at least customize your project id number:

<script>

// <------------------------------------------->
// <------ CRUELIO'S STAT GRAPH SCRIPT -------->
// <------------------------------------------->
// Author: cruelio
// Email: cruelio@msn.com
// Comments: as seen on http://opendreambox.afraid.org. just fill in your
// custom values and insert the script where
// you want the graph displayed



// <------------------------------------------->
// <----- FILL IN YOUR CUSTOM VALUES ---------->
// <------------------------------------------->

var projectId=xxxxxx // Type your project id here
var length=7 // How many days the report should include


// <------------------------------------------->
// <------- DO NOT EDIT BELOW HERE ------------>
// <------------------------------------------->

var img="<img src=\"http://www.statcounter.com/project/standard/graph_daily_summary.php?project_id="+projectId+"&startDate="
var TheDate=new Date()

var TheMonth = TheDate.getMonth() + 1;
if (TheMonth < 10) TheMonth = "0" + TheMonth;

var TheMonthDay = TheDate.getDate();
if (TheMonthDay < 10) TheMonthDay = "0" + TheMonthDay;

var TheYear = TheDate.getYear();
if (TheYear < 1000) TheYear += 1900;

var d2=TheYear+"-"+TheMonth+"-"+TheMonthDay


TheDate.setDate(TheDate.getDate()-length)

TheMonth = TheDate.getMonth() + 1;
if (TheMonth < 10) TheMonth = "0" + TheMonth;

TheMonthDay = TheDate.getDate();
if (TheMonthDay < 10) TheMonthDay = "0" + TheMonthDay;

TheYear = TheDate.getYear();
if (TheYear < 1000) TheYear += 1900;

var d1=TheYear+"-"+TheMonth+"-"+TheMonthDay

img=img+d1+"&endDate="+d2+"&\">"
img="<a href=\"http://www.statcounter.com/project/standard/stats.php?project_id="+projectId+"&guest=1\">"+img+"</a>"

document.write(img)

</script>


tell me what you all think.

regards
cruelio


p.s. happy holidays :D

12-26-2003, 08:01 PM
wow ... we have quite a clever community behind us!

that's ingenius. do you have a live sample somewhere?

cruelio
12-26-2003, 10:45 PM
yes, it is in my forums.
however, you need to register to access them so its only available to members.

here's the link, in case you want to check: http://opendreambox.afraid.org
its in the news and announcement forum, under "forum statistics thread"
it's a bit different from the one i posted, i haven't had a chance to update that one. the one posted here is the latest version, it's better

i hope some people adopt this...
it can be easily modified so that a php script generates this javascript, perhaps have the php script posted right here on stats server. than everyone can use it for example

<script src=http://statcounter.com/generator.php?id=1234&days=7></script>


i dunno, just it would be a nice thing to have, so that everyone could have access to this with little or no know-how....

just my $.02
good luck with your great service!

regards,
cruelio

12-27-2003, 04:18 PM
just to let you know that this will only work for you - your visitors will just see a broken image link if you don't have public stats enabled.

And be sure to check it in another browser, to make sure it will work for all your visitors and not just you.

schnozberry
07-15-2005, 08:09 PM
I've been looking for something like this for my site. Obviously it's pretty old and it doesn't appear to work anymore. Can the code be updated so it works?