Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?


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
Replies are listed 'Best First'.
Re^2: How to create a chart with data from database
by terrykhatri531 (Novice) on Jan 12, 2013 at 08:40 UTC


    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



        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 );


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


      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.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-11-28 14:16 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (742 votes), past polls