Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm not clear what you are trying to do but to create a PivotChart you first need to create a pivot table. Are you trying to create a bar chart of counts for browser types like this ?

#!/usr/bin/perl use strict; use Excel::Writer::XLSX; my $strExcelFilename= 'chart.xlsx'; my $book = Excel::Writer::XLSX->new($strExcelFilename); my $format = $book->add_format(); my $sheet1 = $book->add_worksheet('Data'); my @header = ('User ID','Browser'); for my $col(0..$#header){ $sheet1->write(0,$col, $header[$col], $format); } my $row = 1; my %count=(); # browser count while (<DATA>) { chomp; next unless /\S/; my @f = split ';',$_; ++$count{$f[1]}; $sheet1->write_row($row++,0, \@f); } # add summary chart my $sheet2 = $book->add_worksheet('Summary'); $sheet2->write_row(0,0,['Browser','Count']); $row = 1; for (sort keys %count){ $sheet2->write_row($row++,0,[$_,$count{$_}]); } my $chart = $book->add_chart( type => 'column', embedded => 1 ); $chart->add_series( name => 'Count', categories => '=Summary!$A$2:$A$'.$row, values => '=Summary!$B$2:$B$'.$row, ); $chart->set_title ( name => 'Results of sample analysis' ); $chart->set_x_axis( name => 'Browser' ); $chart->set_y_axis( name => 'Count of Computer' ); $chart->set_style( 11 ); # add chart $sheet2->insert_chart( 'E2', $chart, 25, 10 ); $book->close(); __DATA__ user1;Chrome user2;IE11 user3;IE11 user4;Chrome user5;Firefox user6;IE11 user7;Safari

In reply to Re: Unable to create a Pivot chart with visiable Columns by poj
in thread Unable to create a Pivot chart with visiable Columns by chandantul

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-26 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found