I am using the below code to generate graph and it is working fine.

use strict; use warnings; use Win32::OLE; use Win32::OLE::Const "Microsoft Excel"; my $xls = Win32::OLE->new('Excel.Application'); $xls->Workbooks->Add(); $xls->{Visible} = 1; $xls->Sheets("Sheet1")->Range('A1')->{Value} = 'Left'; $xls->Sheets("Sheet1")->Range('B1')->{Value} = 'Right'; $xls->Sheets("Sheet1")->Range('C1')->{Value} = 'Center'; for (2 .. 5) { $xls->Sheets("Sheet1")->Range("A$_")->{Value} = $_; $xls->Sheets("Sheet1")->Range("B$_")->{Value} = $_ * 2; $xls->Sheets("Sheet1")->Range("c$_")->{Value} = $_ * 3; } $xls->Charts->Add(); $xls->ActiveChart->SetSourceData({ Source =>$xls->Sheets('Sheet1')->Range("A1:C5"), PlotBy =>xlColumns, }); $xls->ActiveChart->Location({ Where => xlLocationAsObject, Name =>'She +et1'});

But what i want to do is, i want give the values through some variable, ie. the chart should not be generated from the excel data, rather i want to create by giving the values through variables or datastructure. for example, i want to create for the below data. I tried as shown below. How can i achieve that?

my @a = (1, 2, 3); my @b = (5, 10, 15); my $a = \@a; my $b = \@b; $xls->ActiveChart->SetSourceData({ Source =>$xls->Sheets('Sheet1')->Range("$a:$b"), PlotBy =>xlColumns, });

In reply to Generate chart in Excel by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.