Skip to content

Implementing alternative renderers for PDF charts #2974

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

Closed
6 tasks
rolinger opened this issue Jul 30, 2022 · 7 comments
Closed
6 tasks

Implementing alternative renderers for PDF charts #2974

rolinger opened this issue Jul 30, 2022 · 7 comments

Comments

@rolinger
Copy link

This is:

- [ ] a bug report
- [ ] a feature request
- [x ] Documentation request

What is the expected behavior?

Examples of using an alternative to jpgraph.

What is the current behavior?

The only reference I can find to using a graphics package is jpgraph which all the documentation states is no longer supported and older versions will cause errors and issues (which I am experiencing).

The only thing I can find is here CpChart

The documents suggest using CpChart as an alternative but I can't find a single reference (google, github, stackoverflow, etc) using cpchart with phpspreadsheet.

Is jpgraph no longer supported at all....even the official download/install package from jpgraph.net?

What are the steps to reproduce?

composer require syzmach/c-pchart

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
use PhpOffice\PhpSpreadsheet\IOFactory ;
use PhpOffice\PhpSpreadsheet\Settings ;
use PhpOffice\PhpSpreadsheet\Chart ;

Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\CpChart::class);  // <--- errors here

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...

What features do you think are causing the issue

  • Reader
  • [ x] Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • [x ] Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Yes

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet: 1.24.1
PHP: 7.3

@rolinger
Copy link
Author

I just found this one comment #2783 (comment) - so I guess the official jpgraph (non-composer) version is supported.

I will try that route now.

Still I think it would be good to have examples of alternatives to jpgraph (especially cpchart since its mentioned in the docs).

@MarkBaker
Copy link
Member

Where is cpchart mentioned in the docs? I've never even heard of cpchart before now

@rolinger
Copy link
Author

If you rely on this feature, please consider contributing either patches to JpGraph or another IRenderer implementation (a good candidate might be [CpChart](https://github.com/szymach/c-pchart)).

https://phpspreadsheet.readthedocs.io/en/latest/topics/migration-from-PHPExcel/#rendering-charts

@rolinger
Copy link
Author

rolinger commented Jul 31, 2022

I found this maintained composer install of jpgraph. https://github.com/mitoteam/jpgraph I installed it but haven't figured out how to get this one to work, I tried the following but errored out on the Settings line:

use mitoteam\jpgraph\MtJpGraph
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraph::class);

@MarkBaker
Copy link
Member

MarkBaker commented Jul 31, 2022

You can't simply throw a class name into the setChartRenderer() and hope that it works: the class passed to setChartRenderer() must be a wrapper class implemented in PhpSpreadsheet as an interface to a rendering library. The only interface that exists is the JpGraph::class interface; and the $rendererLibraryPath argument should point to the base jpGraph library code.

If you rely on this feature, please consider contributing either patches to JpGraph or another IRenderer implementation (a good candidate might be CpChart).

That doesn't mean that an interface exists for CpChart: we'd have to write a wrapper that matched the IRenderer interface (or some contributor would need to submit a PR for such an implementation) for any chart rendering library. It would be nice to have examples for alternatives, but examples are meaningless without that wrapper.

@rolinger
Copy link
Author

I follow now. I guess I read that as contributing patches to JpGraph or user another IRenderer. Rereading I see its contribute to jpgraph or contribute to another IRenderer implementation

Part of my confusion also came from thinking others were already in place based off this:
https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Chart/Renderer/PHP%20Charting%20Libraries.txt

Going to use the jpgraph.net version now.

@rolinger
Copy link
Author

rolinger commented Aug 1, 2022

@MarkBaker @oleibman - as an FYI, I worked with mitoteam/MtJpGraph who has a composer install for JpGraph. They forked PhpSpreadsheet and added a new wrapper/Renderer to work with their composer install of JpGraph. They are using JpGraph 4.4.1. I have it working with my PhpSpreadsheet install now and they will be submitting a new Merge for it shortly.

Makes it a lot easier to install JpGraph...particuarly for users like myself that have Linux cPanel with EashApache4 installed and multiple versions of PHP running - the JpGraph manual install was a lot more complicated than a standard PHP install, so this helps tremendously.

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

No branches or pull requests

2 participants