![]() |
| HTML | PHP Scripts | Webmaster Tools | Webmaster Forums | Web Hosting | Domain Names | Webmaster Books |
|
|
#1 |
|
New Member
Join Date: Aug 2009
Webmaster Discussions: 1
Rep Power: 7 ![]() |
Read Values from CSV and create charts
Hi,
I am new to perl. I have to create charts (XY scatter) from the values from CSV file. Below is the sample file I have. Code:
site,type,2009-01-01,2009-01-02,.... X,A,12,10,... X,B,10,23,... Y,A,20,33,... Y,B,3,12,... and so on.... Can anyone please suggest me some code to start with? |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Apr 2007
Webmaster Discussions: 98
Rep Power: 27 ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Read Values from CSV and create charts
Hey,
I see that you have 4 headings... site type date1 date2 I assume the ...'s indicate there are further dates. Is there a set number of dates or do you need the script to be able to count the number of headings - 2 (therefore the number of dates/headings)? You should first parse the data into a hash table (use the split function) taking into account which type should be included. Then you should use the GD module to produce a graph of the data. A very basic example of parsing the data (I did not test this, and its very rough)... Code:
my $chosentype = 'A';
my $row = 1;
my @headings;
my %hash;
while(<FILE>){
#split the data up by the comma
my ($site,$type,@data) = split(/\,/,$_);
#if the 1st row in the file then use this row for the headings
if ($row == 1){
@headings = @data;
}
#else its actual data
else {
#if the type is the type you want to parse
if ($type eq $chosentype) {
# build the hash (using the row number as a unique identifyer of each row
$hash{$row}{'site'} = $site;
$hash{$row}{'type'} = $type;
foreach (@headings) {
$hash{$row}{$_} = shift(@data);
}
}
}
$row++;
}
Chris |
|
|
|
![]() |
| Bookmarks |
| Tags |
| perl |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Webmaster Discussions
|
||||
| Thread | Webmaster Discussion Starter | Forum | Replies | Last Post |
| Charts | lumpuk | HTML Forum | 0 | 10-25-2007 03:03 AM |
| read file | davidmook | CGI Perl Forum | 0 | 06-29-2006 04:49 AM |
| Read before posting. | HTML | AHFB Feedback and Announcements | 0 | 11-07-2005 09:40 AM |
| Creating Charts in HTML | gdmay | HTML Forum | 4 | 11-11-2002 12:23 AM |