Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to create a chart with data from database

by CountZero (Bishop)
on Jan 12, 2013 at 07:54 UTC ( #1013015=note: print w/ replies, xml ) Need Help??


in reply to How to create a chart with data from database

OK. We take it one step at a time.

First Step: After running your script, do you end up with an Excel spreadsheet file that has the data you want to chart in it? If not, did you get any errors or messages from your script?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: How to create a chart with data from database
Re^2: How to create a chart with data from database
by terrykhatri531 (Novice) on Jan 12, 2013 at 08:40 UTC

    Hi

    First of all thank you very much, yes it does work very well and it does write the data into an excel spreadsheet, now I want to use columns Name, Surfacearea and Population into a chart to be created in the 2nd worksheet of the same excel file.

    If you kindly get me going once I will be very grateful

    Regards

    Terry

        The sample script defines data for the cahrt as under

        # Add the worksheet data that the charts will refer to. my $headings = [ 'Category', 'Values 1', 'Values 2' ]; my $data = [ [ 2, 3, 4, 5, 6, 7 ], [ 1, 4, 5, 2, 1, 5 ], [ 3, 6, 7, 5, 4, 3 ], ]; $worksheet->write( 'A1', $headings, $bold ); $worksheet->write( 'A2', $data );

        Question

        How do I map my data that is retrieved from the database to the chart ?

        Regards

        Terry
      Ok, after studying how the examples work, I have figured out how to map data to the chart, here is the code for my case:
      $worksheet = $workbook->add_worksheet("Population Chart"); $worksheet->add_write_handler(qr[\w], \&store_string_widths); my $chart1 = $workbook->add_chart( type => 'bar', embedded => 1 ); # Configure the series. $chart1->add_series( categories => '=Summary!$A$2:$A$row', values => '=Summary!$G$2:$G$row', name => 'World Population', ); # Add another series. $chart1->add_series( categories => '=Summary!$A$2:$A$row', values => '=Summary!$F$2:$F$row', name => 'World Surface Area', ); # Add some labels. $chart1->set_title( name => 'Results of Population analysis' ); $chart1->set_x_axis( name => 'Countries' ); $chart1->set_y_axis( name => 'Population' ); # Insert the chart into the main worksheet. $worksheet->insert_chart( 'A2', $chart1 ); autofit_columns($worksheet);
      Thank you everyone for your help.

      Regards

      Terry

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-11-26 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls