Viqiko has asked for the wisdom of the Perl Monks concerning the following question:

I have data in my excel file as

Freq SpectrumPsd Freq CpeInterpolVal 0 -44.84071 0 -140 25000 -112.2465 25000 -140 50000 -114.688 50000 -140 75000 -115.3793 75000 -140 100000 -114.9682 100000 -140 125000 -114.1693 125000 -140 150000 -114.0045 150000 -140 175000 -113.3851 175000 -140 200000 -113.559 200000 -140
Now, I want to plot multiple series XYScatter. I provide the code which I'm playing with,
use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; # Start Excel and make it visible # get already active Excel application or open new my $xlApp = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $xlApp->{Visible} = 1; # Open existing workbook my $xlFile = 'C:/wt138.xls'; my $xlBook = $xlApp->Workbooks->Open($xlFile); my $sheet = $xlBook->Worksheets(1); my $chart = $xlBook->Charts->Add; $chart->{ChartType} = xlXYScatterLines; $chart->SeriesCollection->NewSeries; $chart->SeriesCollection(1)->{XValues} = "=Sheet1!A1:A10"; $chart->SeriesCollection(1)->{Values} = "=Sheet1!B1:B10"; $chart->SeriesCollection(1)->{Name} = "=Sheet1!B1"; $chart->SeriesCollection->NewSeries; $chart->SeriesCollection(2)->{XValues} = "=Sheet1!C1:C10"; $chart->SeriesCollection(2)->{Values} = "=Sheet1!D1:D10"; $chart->SeriesCollection(2)->{Name} = "=Sheet1!E1"; $chart->{ChartTitle} = "Freq Vs. Psd";
I'm not getting the xyscatter plot with 2 series included. Please help.

Replies are listed 'Best First'.
Re: Need to make a plot (XYscatter) in Excel
by xyzzy (Pilgrim) on Feb 23, 2010 at 20:43 UTC

    help with what? you need to explain what your problem is. if you don't know what your problem is then it would probably help to throw in or die $! (see below) wherever you think there could be a problem, use warnings and diagnostics, or try using the debugger (-d in the command line).

    I don't remember exactly which ones, but a lot of the OLE functions return 0 or undef on a success (as if using perl in a windows environment is not annoying enough already) so make sure you RTFM so you know if you need to use  and die in those cases


    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    Happy, sober, smart: pick two.