Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart overwriting user supplied options #121

Closed
rdboisvert opened this issue Jan 20, 2015 · 5 comments
Closed

Chart overwriting user supplied options #121

rdboisvert opened this issue Jan 20, 2015 · 5 comments
Assignees

Comments

@rdboisvert
Copy link

John,

It appears that the add_series () function for charts overwrites the value of trendline->{line}->{dash_type}. This doesn't cause a problem if literals are used. However, in my case I want to set a trendline on several charts by passing a hash to the function (see below). This results in a message that says something like "Unknown dash type 'sysDash'" and the trendline loses all the line values I set.

I was able to put a quick patch in Chart.pm that adds the transformed names to %dash_types which works around my coding issue. Another solution is to not transform the original hash passed to the function.

Would it be possible for you to correct this issue?

Thanks,
Bob

Failing Code

my %oProps =
  (
  name => $oSeries [$nCol]->{label},
  categories => [$oCmp->{sheet}, $nFirstRow, $nLastRow, 0, 0],
  values => [$oCmp->{sheet}, $nFirstRow, $nLastRow, $nCol + 1, $nCol + 1],
  );
if (exists $oSeries [$nCol]->{trendline})
  { $oProps {trendline} = $oSeries [$nCol]->{trendline}; }
$oChart->add_series (%oProps);

Quickfix Change to Chart.pm

my %dash_types = (
  solid               => 'solid',
  round_dot           => 'sysDot',
  square_dot          => 'sysDash',
  dash                => 'dash',
  dash_dot            => 'dashDot',
  long_dash           => 'lgDash',
  long_dash_dot       => 'lgDashDot',
  long_dash_dot_dot   => 'lgDashDotDot',
  dot                 => 'dot',
  system_dash_dot     => 'sysDashDot',
  system_dash_dot_dot => 'sysDashDotDot',

  sysDot              => 'sysDot',
  sysDash             => 'sysDash',
  dashDot             => 'dashDot',
  lgDash              => 'lgDash',
  lgDashDot           => 'lgDashDot',
  lgDashDotDot        => 'lgDashDotDot',
  sysDashDot          => 'sysDashDot',
  sysDashDotDot       => 'sysDashDotDot',
);
@jmcnamara
Copy link
Owner

Hi,

Thanks for the report.

Could you add a small but complete example that demonstrates the issue and I'll have a look at it.

Regards.

John.

@rdboisvert
Copy link
Author

Here is a simple example that is probably familiar to you. :{)

    use Excel::Writer::XLSX;

    my $workbook = Excel::Writer::XLSX->new ('trendlinebug.xlsx');
    my $worksheet = $workbook->add_worksheet ('Trendline');
    my $headings = [ 'Number', 'Batch 1', 'Batch 2' ];
    my $bold = $workbook->add_format (bold => 1);
    my $data = [
      [ 2, 3, 4, 5, 6, 7 ],
      [ 10, 40, 50, 20, 10, 50 ],
      [ 30, 60, 70, 50, 40, 30 ],
    ];
    my $trend = {
      type => 'linear',
      line => { color => 'red', dash_type => 'square_dot' }
    };
    $worksheet->write ('A1', $headings, $bold);
    $worksheet->write ('A2', $data);
    my $chart = $workbook->add_chart (type => 'line', embedded => 1);
    $chart->add_series (
      name       => '=Trendline!$B$1',
      categories => '=Trendline!$A$2:$A$7',
      values     => '=Trendline!$B$2:$B$7',
      trendline  => $trend,
      );
    $chart->add_series (
      name       => '=Trendline!$C$1',
      categories => [ 'Trendline', 1, 6, 0, 0 ],
      values     => [ 'Trendline', 1, 6, 2, 2 ],
      trendline  => $trend,
      );
    $worksheet->insert_chart ( 'D2', $chart);
    $workbook->close ();

@jmcnamara
Copy link
Owner

Hi,

Thanks for the example. It is always easier to understand working code.

That is a bug but it should be an easy fix. I'll let you know when it is available.

John

@jmcnamara jmcnamara added the bug label Jan 21, 2015
@jmcnamara jmcnamara self-assigned this Jan 21, 2015
@jmcnamara jmcnamara changed the title Chart trendline->{line}->{dash_type} Changed Chart overwriting user supplied options Jan 21, 2015
jmcnamara added a commit that referenced this issue Mar 2, 2015
Fix to copy user defined chart properties, such as trendlines,
so that they aren't overwritten.

Issue #121.
@jmcnamara
Copy link
Owner

Hi,

Sorry, it took a while to get around to fixing this.

I've push a fix to master along with a test based on your sample program. If you get a chance you can test it as well.

John

@rdboisvert
Copy link
Author

John,

I tested the version I downloaded on March 3 and it solved the bug and has not exhibited any other problems.

Thank you for resolving this,
Bob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants