szymach / c-pchart Goto Github PK
View Code? Open in Web Editor NEWA project bringing Composer support and PSR standards to pChart 2.0 library.
Home Page: http://www.pchart.net/
License: GNU General Public License v3.0
A project bringing Composer support and PSR standards to pChart 2.0 library.
Home Page: http://www.pchart.net/
License: GNU General Public License v3.0
Another early heads-up:
Deprecated - Implicit conversion from float 74.08333333332371 to int loses precision
Line 288 in c71e1d8
Line 510 in c71e1d8
Line 1312 in c71e1d8
PHP Deprecated: Function utf8_encode() is deprecated in .../vendor/szymach/c-pchart/constants.php on line 48
Line 48 in 373786c
If I understand it correctly utf8_encode("€")
is the same as "€"
(see https://3v4l.org/dERVv), so I think the utf8_encode()
can simply be removed.
There is an eval call that I really do not like. Needs to be replaced.
I have wiped all labels and axis information to create just pure graphic charts. See example of graph style here. Simple math error because I have 0 points to draw on.
In various places I see "throw new Exception". This doesn't work within namespaces. Should be "throw new \Exception" (with the backslash added).
I know there is an open issue around PHP 8.1 as well as a pull request about the same, but I'm hoping you'll reconsider support for PHP8.1, especially since symfony 6.1 will require PHP 8.1. I would love to be able to continue using your libraries going forward. Thanks very much.
The line shows:
$DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
But it should be:
$DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
Line 7259 in 3e04e49
Just an early heads-up:
Using the PHP8.1 beta2 the following deprecation warning is shown:
Deprecated - imagefilledpolygon(): Using the $num_points parameter is deprecated
Lines 81 to 83 in c71e1d8
see also https://www.php.net/manual/en/function.imagefilledpolygon.php
There are multiple places when the result of scaleComputeY
is used as parameters of function, that expect integers. This may yield unexpected results or errors.
Hi,
fisrt of all, tx for mantaining this library, it really saved me. I've done a pie chart and I'd like to show the percentage of each sector, acording to the documentation by setting WriteValues
to true
or PIE_VALUE_PERCENTAGE
, but, probably due to something I'm missing, the image doesn't shows anything.
$factory = new CpChart\Factory\Factory();
function generatePieChart($factory, $data, $title = '', $name = 'pie.png', $width = 500, $height = 500, $titleHeight = 20, $legend = false) {
// Set Data
$chartData = $factory->newData(array_values($data),"Participantes / Genero");
$chartData->setSerieDescription("Participantes / Genero","Participantes por genero");
$chartData->addPoints(array_keys($data), "Labels");
$chartData->setAbscissa("Labels");
// Create the pChart object
$picture = $factory->newImage($width, $height, $chartData);
// Draw a solid background
$picture->drawFilledRectangle(0, 0, $width, $height, array("R" => 255, "G" => 255, "B" => 255));
$picture->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 0,"StartG" => 0,"StartB" => 0,"EndR" => 50,"EndG" => 50,"EndB" => 50,"Alpha" => 100));
// Add a border to the picture
$picture->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0));
// Write the picture title
$picture->setFontProperties(array("FontName" => "Silkscreen.ttf", "FontSize" => 7));
$picture->drawText(10, 15, $title, array("R" => 255, "G" => 255, "B" => 255));
// Set the default font properties
$picture->setFontProperties(array("FontName" => "Forgotte.ttf", "FontSize" => 10,"R" => 80, "G" => 80, "B" => 80));
// Create the chart
$chart = $factory->newChart("pie", $picture, $chartData);
// Conf the chart
$chart->draw2DPie(floor($width / 2), floor($height / 2), array("Radius" => 160, "DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE, "WriteValues" => PIE_VALUE_PERCENTAGE));
// Legend Box
if ($legend) {
$picture->setShadow(FALSE);
$chart->drawPieLegend(15, 40, array("Alpha" => 20));
}
$picture->Render($name);
}
generatePieChart($factory, array('Male' => 16, 'Female' => 8), 'By Gender');
Just to sum up, the important part would be:
$chart->draw2DPie(floor($width / 2), floor($height / 2), array("Radius" => 160, "DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE, "WriteValues" => PIE_VALUE_PERCENTAGE));
and the result (not showing the percentage values):
No pBar class
Can you fix that?
In composer.json, you have updated the dependency some time ago from PHP 5.3 directly to PHP 5.5.
Could that dependency be brought back to PHP 5.4?
We use your lib in Chamilo (a large e-learning platform) and we plan on maintaining the current version with support for PHP 5.4. However, we also want to support 7.0 and 7.1. Supporting PHP 7 implies using version 2 of c-pchart, but this one depends on PHP 5.5, which would force us to choose between supporting 5.4 and supporting 7.0.
Can you see the difficult choice we face?
I haven't checked the c-pchart 2 in PHP 5.4 yet, to check if it works, but thought that maybe you would still remember what forced you to move to 5.5 or if it was just a decision without a specific reason behind it...
When you want to draw a pie chart, you have the option to display absolute or percentage values on the chart.
$Format['WriteValues']
to PIE_VALUE_NATURAL
;$Format['WriteValues']
to PIE_VALUE_PERCENTAGE
;I'd like to add an option to display both absolute and percentage values on the chart. I propose to display this as follows:
4
(20%)
I propose to set $Format['WriteValues']
to PIE_VALUE_BOTH
when you want both absolute and percentage values to be displayed.
I will create a pull request shortly.
When viewing https://github.com/szymach/c-pchart , the upper right of the page says that this package is licensed MIT, but the README and upstream pchart package are not licensed MIT. This caused confusion when packaging this library for Fedora:
This was a hacky attempt to ease the use of the library and should not be used.
my code:
`
require "vendor/autoload.php";
use CpChart\Chart\Radar;
use CpChart\Data;
use CpChart\Image;
error_reporting(E_ALL | E_STRICT);
ini_set("log_errors", "on");
ini_set("display_errors", "on");
$values = [
9,
9.29,
10,
10,
8.5
];
$width = 400;
$height = 400;
$data = new Data;
$data->addPoints($values, "Score");
$data->setSerieDescription("Score", "222");
$data->addPoints(["111", "222", "333", "444", "555"], "Labels");
$data->setAbscissa("Labels");
$data->setPalette("Score", ["R" => 157, "G" => 96, "B" => 22]);
$image = new Image($width, $height, $data);
$image->setFontProperties(["FontName" => 'resource/fonts/SourceSansPro-Regular.ttf', "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$radar = new Radar;
$image->setGraphArea(0, 0, $width, $height);
$options = ["DrawPoly" => true, "WriteValues" => true, "ValueFontSize" => 7, "Layout" => RADAR_LAYOUT_CIRCLE, "BackgroundGradient" => ["StartR" => 255, "StartG" => 255, "StartB" => 255, "StartAlpha" => 100, "EndR" => 207, "EndG" => 227, "EndB" => 125, "EndAlpha" => 50]];
$radar->drawRadar($image, $data, $options);
`
php:
php -v PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:03) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.0, Copyright (c) Zend Technologies with Zend OPcache v8.1.0, Copyright (c), by Zend Technologie
errors:
`
Deprecated: Implicit conversion from float 216.6 to int loses precision in /var/www/test/vendor/szymach/c-pchart/src/BaseDraw.php on line 288
Deprecated: Implicit conversion from float 232.6 to int loses precision in /var/www/test/vendor/szymach/c-pchart/src/BaseDraw.php on line 288
Deprecated: Implicit conversion from float 52.80000000000001 to int loses precision in /var/www/test/vendor/szymach/c-pchart/src/Draw.php on line 1145
Deprecated: Implicit conversion from float 52.80000000000001 to int loses precision in /var/www/test/vendor/szymach/c-pchart/src/Draw.php on line 1146
Deprecated: Implicit conversion from float 216.6 to int loses precision in /var/www/test/vendor/szymach/c-pchart/src/BaseDraw.php on line 288
`
install v3.0.11:
`
"name": "szymach/c-pchart",
"version": "v3.0.11",
"source": {
"type": "git",
"url": "https://github.com/szymach/c-pchart.git",
"reference": "7022fa093ca142bbe9705504420d30073a5ddf13"
},
After upgrading to PHP 7.1, pie charts are not fully rendered. Labels are in place, but the actual plots are missing from generated images.
Hi,
what is the license of this library? The compose file state MIT, but some classes contain a reference to http://www.pchart.net/license
Hello,
I have a question :
Is there a way to increase the radius of the position of my pie chart Value?
Right now it looks like this :
And though it is nice, I would like to push the values near the external border of the pie. In your Pie class code, I saw this :
if ($ValuePosition == PIE_VALUE_OUTSIDE) { $Xc = cos(($Angle - 90) * PI / 180) * ($Radius + $ValuePadding) + $X; $Yc = sin(($Angle - 90) * PI / 180) * ($Radius + $ValuePadding) + $Y; } else { $Xc = cos(($Angle - 90) * PI / 180) * ($Radius) / 2 + $X; $Yc = sin(($Angle - 90) * PI / 180) * ($Radius) / 2 + $Y; }
I assumed it was the position of the values depending on the $ValuePosition referenced in the $Format array parameter.
I was wondering if for those lines :
$Xc = cos(($Angle - 90) * PI / 180) * ($Radius) / 2 + $X; $Yc = sin(($Angle - 90) * PI / 180) * ($Radius) / 2 + $Y;
we could set another parameter from $Format, something like 'ValueRadius' which would replace ($Radius)/2
.
Thanks,
Since all the JavaScript is gone there is no point in keeping the ImageMap functions
I'm getting the above mentioned fatal error with CpChart 3.0.0 and PHP 7.1.6.
The reason is that BaseDraw
initialises a variable $Width = ""
, but uses it like an array
:
Lines 763 to 784 in 08a2937
Hello!
I have been working on packaging this library for Fedora, but we came across a licensing conundrum: due to the wording in pChart's license about making money and commercial use, there is a logical contradiction in the licensing:
If person A is non-commercial and uses pChart under the GPL, can they then give pChart to comany B who will make money under it? The GPL says "of course", but the pChart license excludes this possibility.
I attempted to contact the pChart authors a week ago to ask them to alter the wording on their license page, but I have not heard back from them. If you know how to get in touch with them, I encourage you to do so.
Here is the message I sent them last week:
Hello!
I work on the Fedora Project[0] and I am interested in packaging pchart
for Fedora. There is some confusing language on the pchart licensing
page[1] around whether the GPL license is truly GPL or not, as it has a
statement about whether money is made or not. The GPL does not prevent
making money with the software, it just has rules about what can and
can't be done with the software that isn't particularly friendly
towards closed source use.
Unfortunately, the use of the word commercial and the "you make money
by distributing it" statement means that pchart isn't truly GPL, as the
GPL does not restrict profit and in fact it is not compatible with the
idea of restricting profits. I brought this issue up on Fedora's legal
mailing list, and it was ruled that pchart cannot be distributed with
Fedora due to the statement[2]. One of the replies on the thread was
from Richard Fontana[3], a notable authority on GPL licensing.
This statement causes a paradox as well - suppose that person A accepts
pchart under the GPL (and person A does not make money with it).
Suppose then that person A gives pchart to company B under the terms of
the GPL (which they have the right to do with the GPL they were given)
and then company B makes money off of it, while abiding by the GPL. Is
company B violating the license? The wording on the license page makes
this situation unclear.
However, after reading some forum posts about the license[4] I came to
believe that perhaps the license page was intended to communicate that
the library is publicly licensed GPL for any use allowed by the GPL
(including making money as a commercial entity), but that pchart was
available under other licenses for a fee if someone wanted to
distribute pchart with or as closed source software. There are other
examples of this style of dual licensing, but they typically don't use
wording about commercial use or making money. Is this the intention of
the license? If so, would you be willing to adjust the wording on that
page? Without an adjustment, this library won't be allowed to be part
of the Fedora project.
[0] https://getfedora.org/
[1] http://www.pchart.net/license
[2] https://lists.fedoraproject.org/archives/list/[email protected]/thread/4MDAWLRSVR3QIIYFJLVKMEELS5OPBIMI/
[3] https://en.wikipedia.org/wiki/Richard_Fontana
[4] http://wiki.pchart.net/forum/viewtopic.php?f=3&t=2163&p=3784&hilit=license#p3784
I tried to set the axis name in bar chart but unfortunately only index 0 is set and can't set axis name for index 1
http://wiki.pchart.net/doc.chart.drawbarchart.html
$data = new Data();
$data->addPoints([-4, VOID, VOID, 12, 8, 3], "Probe 1");
$data->addPoints([3, 12, 15, 8, 5, -5], "Probe 2");
$data->addPoints([2, 0, 5, 18, 19, 22], "Probe 3");
$data->setSerieTicks("Probe 2", 4);
$data->setAxisName(0, "Temperatures");
$data->addPoints(["Jan", "Feb", "Mar", "Apr", "May", "Jun"], "Labels");
$data->setSerieDescription("Labels", "Months");
$data->setAxisName(1, "Months");
$data->setAbscissa("Labels");
Actually when I check print_r($data); and exit; then I seen that index 1 is not set when I called that function so request you to please fix that issue
After upgrading to PHP 7.1, the function loadPalette() in Data.php does not correctly load external palettes. This is fixed by forcing (int) type on the numbers read in on line 907:
$this->Palette[$ID] = ["R" => (int) $R, "G" => (int) $G, "B" => (int) $B, "Alpha" => (int) $Alpha];
without the fix, this results in strings for the values in the Palette array, and in particular the $Alpha is loaded as "100\n", yielding a PHP error "a non well formed numeric value".
Hi,
We still use pChart and we'd like it to support PHP 7.1 (it is currently broken). In the eventuality that we would continue using it an maintain it, would you accept PRs, or would you prefer us to fork it and maintain it apart from you?
How to create char bart?
I am doing:
$bar = $factory->newChart('Bar', $myPicture, $myData);
But the intenal exception is triggered:
`The requested chart is not a seperate class, to draw it you need to call the "drawBarChart" method on the Image object after populating it with data! Check the documentation on library's website for details.Done
If I call in image to drawBarChart it says:
$myPicture->drawBarChart([])
There was an error: Notice: Undefined index: FormatDone
`
I'm placing this here more for anyone who comes after me than to expect a solution.
It appears that, for whatever reason, drawLine() ignores setSerieWeight() if neither anti-aliasing nor a dashed (ticks) line are requested. My best guess is that the author thought that thick lines looked bad without these settings. Or it could have just been an oversight.
There's an old question about this on the "official" (dead?) pChart forum: http://wiki.pchart.net/forum/viewtopic.php?f=5&t=2316&hilit=setserieweight
I found no harm when commenting out this clause in drawLine() to let it fall through to the code that handles the weight.
if ( $this->Antialias == FALSE && $Ticks == NULL )
{
if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
{
$ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
imageline($this->Picture,$X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$ShadowColor);
}
$Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
imageline($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
return(0);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.