1

I want to make a bar diagram on my website that shows what days of the week and times-of-day has the most activity/logins.

So i'm wondering if someone could give me some tips on how they would do this? How i should organize the database table(s), what data to gather, and how i can present the data recorded as a bargraph using PHP.

Kanonskall
  • 423
  • 1
  • 4
  • 11
  • 3
    Start by telling us what data you already have? Do you log website visitors? Are you using any analytics packages (like google analytics)? Etc. – rlb.usa Nov 23 '10 at 16:49
  • My main problem is figuring out how my database table(s) should be organized. I will then record at what day and time of the day a login/visit occured with PHP, and use that data to present a bar graph on the website, so my visitors can see at what times my website has the most activity (it's a chat page). I'm not sure what you mean by what data i already have. – Kanonskall Nov 23 '10 at 16:56

3 Answers3

1

Might be easier to do a visualisation using your server logs. Processing ( http://www.processing.org/ ) is good at things like that, or try http://processingjs.org/ for a non Java version.

To address your question though, as has been mentioned, store the data time for each visit (and maybe IP as well if you're after unique visits) then write a script to pull the records and do a total for each hour. You could use coloured divs, with the height set to the number (or a fraction) of the hits. Actually this is basically a hit counter isn't it.

Yeah, my advice would be to check out processing though, it's easy to pick up and produces nice looking results.

Robimp
  • 704
  • 6
  • 13
  • 29
0

Probably the best way to do this is to store a datetime stamp for each visit or login. Then, you can use clever SQL queries to group the information however you want (days of week, times of day, or anything else.)

So, the database table would likely only need a primary key and the timestamp of the visit, though you could definitely store information about the user or the action as well.

For presentation, try either Google Charts (http://code.google.com/apis/chart/) or a javascript-based charting library (There are several out there, I've had good experience with Highcharts http://www.highcharts.com/)

ps: Since you flagged this post as MySQL, I'm assuming that's your database of choice. Here is a table creation statement you can use.

CREATE TABLE `visits` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `created` datetime NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Chase Finch
  • 5,161
  • 1
  • 21
  • 20
  • Sure. He did mention, however, that he's interested in logins - those can be handled a bit more accurately than page visits without needing to make sure the IP is unique. – Chase Finch Nov 23 '10 at 17:11
  • Not seen highcharts before, that looks like a good option @Kanonskall – Robimp Nov 23 '10 at 17:11
  • yeah true, though I think he's after logins and plain old visits as well. I might be wrong though. – Robimp Nov 23 '10 at 17:13
0

If you must do it yourself and not use a pre-existing package. Start small. Simply create one table that logs each request, who made it, the time, the referer, whatever info you want.

Once you have the data logged, if you still don't want to use something like Google Charts you can try making your own simple PHP charts with css and html.

Bar diagrams can be pretty easy, but require some math to get right. The easiest way is to flip them on their side. You normally see them like buildings, but you want in this case to see them as worm-like tubes. The length of the tube can then represent the number of hits, pageviews, visits, so on.

I would define a fixed width for the whole chart and change the width of the bars to represent a percentage of the max value. So if the max value is 1000, and this bar is 500, you would make the bar 50% of the width of your chart.

I hope this points you in the right direction. Doing something like this can be great for learning new concepts.

DampeS8N
  • 3,621
  • 17
  • 20