Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How to creata a Line Graph

by azaragoza (Acolyte)
on Sep 16, 2008 at 21:18 UTC ( #711805=perlquestion: print w/ replies, xml ) Need Help??
azaragoza has asked for the wisdom of the Perl Monks concerning the following question:

I need to create a line graph from two or more results, I found some examples, but I don't know how to enter the data into the charts and the documentation is limited. Some of the more intuitive examples create .png graphs and they won't display on my Windows XP/Vista machines. Can someone guide me to where I can find examples of line graphs or much better list one with an explanation of how to enter the data to be displayed. I'm very new to perl programming, thanks.

Comment on How to creata a Line Graph
Re: How to creata a Line Graph
by kyle (Abbot) on Sep 16, 2008 at 21:25 UTC
      I have used GD::Graph::lines, and found it very easy to use. It can also generate gif or jpg format files instead of png. I got it working pretty easily, and the web page for the module is very helpful.
      Thanks the GD::Graph::lines Graph worked it created a file that I can display. Here is what I'm trying to graph: Net Debit - Premiums Bought - Premiums sold (47.375 + 7.625) - 21.125 = 33.875 Max Risk - Net Debit 33.875 = $1,693.75 Max Reward - Difference in adjacent strikes - net debit 60 - 33.875 = 26.125 = 5000 X .26125 = $1,30625 Breakeven Down - Lower Strike + net debit 640 + 33.875 = 673.875 Breakeven Up - Higher strike - net debit 760 - 33.875 = 726.125 or 733.875 If entered below curent Strike price Max ROI 290.63% if the stock is priced at $700.00 at expiration How do I enter it into the code: <code> @data = ( "1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th", 1, 2, 5, 6, 3, 1.5, 1, 3, 4, sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ); <code>
Re: How to creata a Line Graph
by MidLifeXis (Prior) on Sep 16, 2008 at 21:26 UTC

    Have you taken a look at gnuplot? It is a non-perl solution, but can do some nice line graphs.

    Also see Chart::Gnuplot.

    --MidLifeXis

Re: How to creata a Line Graph
by jmcada (Acolyte) on Sep 17, 2008 at 00:40 UTC
    Take a look at Chart::OFC. It uses a free flash widget that you feed a data file to. Chart::OFC creates that data file. There is a presentation that shows some basic usage. Also, here is some code for a line chart:
    use warnings; use strict; use Chart::OFC; my ( @data1, @data2, @data3 ); for ( 1 .. 1200 ) { push @data3, 1 + int( rand(7) ); push @data2, 8 + int( rand(6) ); push @data1, 14 + int( rand(6) ); } my $chart = Chart::OFC::Grid->new( title => 'Many data lines', title_style => '{font-size: 20px; color: #736AFF}', datasets => [ Chart::OFC::Dataset::Line->new( values => \@data1, width => 2, color => '#9933CC', label => 'Page Views', text_size => 10, ), Chart::OFC::Dataset::LineWithDots->new( values => \@data2, solid_dots => 1, width => 3, color => '#CC3399', label => 'Downloads', text_size => 10, dot_size => 5, ), Chart::OFC::Dataset::LineWithDots->new( values => \@data3, solid_dots => 0, width => 2, color => '#80a033', label => 'Bounces', text_size => 10, dot_size => 4, ), ], x_axis => Chart::OFC::XAxis->new( labels => [ qw(January February March April May June July August September October November December) ], axis_label => '', orientation => 'horizontal', label_steps => 2, ), y_axis => Chart::OFC::YAxis->new( axis_label => Chart::OFC::AxisLabel->new( label => 'Open Flash Chart', text_size => 12, text_color => '#736AFF', ), min => 0, max => 20, label_steps => 5, ), ); print $chart->as_ofc_data();
      I tried running this code on Win32 XP and got the following: E:\PerlGraphs>perl E:\PerlGraphs\OFCChart.pl &title=Many data lines,{ {font-size: 20px; color: #736AFF} }& &x_legend=,20,#000000& &x_labels=January,February,March,April,May,June,July,August,September,October,November,D ember& &x_label_style=10,#784016,0,2& &y_legend=Open Flash Chart,12,#736AFF& &y_label_style=10,#784016& &y_ticks=5,10,4& &y_min=0& &y_max=20& &line=2,#9933CC,Page Views,10& &values=15,15,18,18,17,15,14,14,18,19,15,16,14,14,14,16,18,16,16,14,19,18,15,16,16,19,15 8,16,18,18,16,19,18,16,14,17,17,14,15,18,15,19,15,14,14,19,17,16,15,17,19,14,15,16,16,18 9,16,15,16,17,19,18,15,14,14,14,19,19,18,16,19,18,16,15,16,19,18,14,18,18,19,16,18,17,14 5,16,19,18,14,18,19,14,15,15,17,15,17,18,17,16,14,18,14,14,19,17,18,14,19,17,18,17,18,17 5,17,15,14,15,16,15,14,15,17,17,17,14,17,17,17,16,14,18,18,15,17,15,19,19,16,19,17,19,19 8,18,14,19,19,19,16,14,18,17,16,14,16,16,17,17,15,16,14,15,16,14,17,16,15,16,18,18,17,16 4,16,15,14,17,18,16,17,19,19,18,19,17,17,15,19,14,14,15,17,15,15,17,15,16,18,17,14,16,18 5,14,14,18,14,16,19,16,16,18,16,19,14,14,15,14,16,19,18,16,15,17,17,19,17,14,14,16,18,14 6,18,14,15,17,19,14,15,14,19,19,19,15,17,16,16,16,17,19,16,17,14,15,19,14,19,16,18,19,16 9,14,14,18,14,15,18,17,19,17,17,19,14,18,17,15,19,19,14,17,15,16,14,14,18,19,15,15,19,16 6,17,17,15,14,16,18,17,15,14,15,17,18,19,16,16,18,19,14,18,15,16,16,17,19,15,15,17,16,15 8,17,18,14,19,18,17,19,18,19,15,17,18,19,19,16,18,17,16,15,18,16,18,18,17,17,18,18,19,15 8,19,16,14,18,17,14,16,15,15,14,15,16,18,19,17,17,17,14,14,16,14,18,14,17,16,18,19,17,19 7,19,19,19,14,18,18,19,15,18,17,15,19,17,14,18,15,14,18,15,19,15,16,18,17,15,19,15,19,14 8,19,14,16,14,18,18,14,15,15,17,16,15,18,14,18,14,18,16,16,16,17,18,14,15,16,17,18,18,16 9,17,16,18,14,16,19,15,15,16,18,15,14,14,18,15,14,19,18,16,15,17,17,19,16,17,19,17,18,19 5,15,15,17,14,18,17,15,18,15,19,16,14,18,17,18,17,18,16,15,18,14,19,17,14,19,15,16,14,19 5,14,17,19,19,15,14,14,19,19,16,19,15,14,17,18,15,18,18,19,14,14,17,18,14,16,16,19,18,16 8,14,16,18,19,14,14,17,18,17,17,15,14,15,16,18,14,14,19,18,17,15,14,15,14,19,15,17,19,14 7,14,17,14,19,14,16,18,17,19,17,18,18,18,16,19,14,17,14,15,16,16,19,17,14,19,18,18,17,14 6,15,18,16,19,18,17,15,15,15,14,19,14,17,15,18,15,16,15,17,18,17,17,17,17,14,18,18,18,17 5,19,17,16,17,16,16,18,14,15,18,14,14,16,17,19,19,16,14,15,14,17,15,17,19,14,16,17,15,17 Any ideas?
        That's what you want to see :) Just write that to a data file (or serve it dynamically) to a file linked to by the OFC Flash object.
Re: How to creata a Line Graph
by planetscape (Canon) on Sep 17, 2008 at 04:06 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://711805]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-12-29 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls