Your SSCCE was neither self-contained nor correct/compilable.

To be able to help you, I added the use-modules at the top, plus I aliased the CSV bareword-filehandle to the built-in DATA bareword-filehandle, so that reading from <CSV> will actually read from the __DATA__ section at the end of the file:

#!perl use 5.012; # strict, // use warnings; use Excel::Writer::XLSX; *CSV = *DATA; # makes CSV an alias to the __DATA__ section, so I can + add CSV data to the end of the script, rather than creating a separa +te file; you will not want this line in your application
... to the top. And then I created the __DATA__ section at the end of the script, with some CSV-style data:
__DATA__ freq,b xtalk 10,0.000001 20,0.000002 50,0.000005 100,1.00E-05 200,2.00E-05 500,5.00E-05 1000,1.00E-04

(I only did columns A:B; data in C:E wasn't necessary to prove that the legend and chart will work.)

For your program, you won't need the *CSV = *DATA, nor the __DATA__ section at the end, because presumably you already opened CSV in some line of code not shown to us. (Read perldoc -f open, and learn to use lexical filehandles rather than the old-fashioned bareword filehandles. And don't forget to check for success on your open: it's easiest to do that automatically by using use autodie;)

With the solidfill legend code in there, it gives me the warning

Can't use string ("solidfill") as a HASH ref while "strict refs" in us +e at c:/usr/local/apps/berrybrew/perls/system/perl/site/lib/Excel/Wri +ter/XLSX/Chart.pm line 1158.
and doesn't create the chart at all. If I comment that out, so none of the set_legend calls are active, I get a chart that I think matches your expectation (though the legend is on the center-right and isn't formatted).

I don't know where you got fill=>'solidfill', as I don't see "solidfill" anywhere in the chart formatting section. I tried

$chart->set_legend( position => 'overlay_top_right', fill => { color => 'red' }, );
... and it put it over the chart in the top right with a red background, which is what I'd expect.

You claimed

#$chart->set_legend({ 'font'=> { 'bold' => 1, 'italic' => 1}}); <<== t +aken from CPAN example, it generates error
... but the documentation actually says in the set_legend() section,
$chart->set_legend( font => { bold => 1, italic => 1 } );
... Notice, it only has one pair of braces, not two like in your code. Using exactly the line that the POD shows, I get a legend on the far right whose labels are bold and italic.

Combining it all together

$chart->set_legend( position => 'overlay_top_right', fill => { color => 'red' }, font => { 'bold' => 1, 'italic' => 1}, );

I get upper right, red background, bold and italic, exactly as I would expect.


In reply to Re^3: XLSX::Chart legend question by pryrt
in thread XLSX::Chart legend question by smh

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.