
The Code
- #!/usr/bin/perl
- use 5.010 ;
- use strict ;
- use warnings ;
- use Chart::Clicker;
- use Chart::Clicker::Data::Series;
- use Chart::Clicker::Data::DataSet;
- my $pi = 3.14159265358979;
- sub deg_to_rad { ($_[0]/180) * $pi }
- sub rad_to_deg { ($_[0]/$pi) * 180 }
- my @core = ( 0 .. 1_000 ) ;
- my @sine ;
- my @cosine ;
- for my $a ( @core ) {
- push @sine , sin(deg_to_rad($a)) ;
- push @cosine , cos(deg_to_rad($a)) ;
- }
- my $cc = Chart::Clicker->new;
- my $series1 = Chart::Clicker::Data::Series->new(
- keys => \@core ,
- values => \@sine
- );
- my $series2 = Chart::Clicker::Data::Series->new(
- keys => \@core ,
- values => \@cosine
- );
- my $dataset = Chart::Clicker::Data::DataSet->new(
- series => [ $series1 , $series2 ],
- );
- $cc->add_to_datasets($dataset) ;
- $cc->write_output('graph_test.png');
- exit ;
There's lots of ways to do graphs. The way we do some graphs here is to do a system call to R. R is powerful, sure, but there's no good way to set up a batch of complex graphs in Perl and send them to R for graphing. There are ways, sure, but not good ways. So, I expect to do a lot more with Chart::Clicker in the future.
No comments:
Post a Comment