Git Product home page Git Product logo

c-pchart's People

Contributors

bowlofeggs avatar bozhinov avatar caugner avatar eclipxe13 avatar edlerd avatar funkjedi avatar iansltx avatar jamesleesaunders avatar magnusjt avatar rage28 avatar sgiehl avatar subtronic avatar szymach avatar thadafinser avatar ywarnier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-pchart's Issues

PHP8.1: Implicit conversion from float to int loses precision

Another early heads-up:

Deprecated - Implicit conversion from float 74.08333333332371 to int loses precision

return imagecolorallocatealpha($Picture, $R, $G, $B, $Alpha);

return $Value1 % $Value2;

imagettftext($this->Picture, $FontSize, $Angle, $X, $Y, $C_TextColor, $FontName, $Text);

see https://wiki.php.net/rfc/implicit-float-int-deprecate

Exceptions not namespaced

In various places I see "throw new Exception". This doesn't work within namespaces. Should be "throw new \Exception" (with the backslash added).

PHP 8.1 support

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.

Wrong array key referenced

The line shows:
$DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
But it should be:
$DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;

$DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;

PIE_VALUE_PERCENTAGE not working

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):

pie

Is the dependency on PHP 5.5 really necessary?

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...

Add an option to display both absolute and percentage values in pie chart

When you want to draw a pie chart, you have the option to display absolute or percentage values on the chart.

  • For displaying a value as absolute you set $Format['WriteValues'] to PIE_VALUE_NATURAL;
  • For displaying a value as percentage you set $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.

Documentation updates

  • Extract changelog to a separate file.
  • Move examples into separate files.
  • Add an example for each chart.
  • Entry on using cache.
  • Entry on barcodes.
  • Image and/or link to offical wiki for each chart.
  • Add code coverage and scrutinizer score to README.
  • Zone chart entry missing.

packagist

I don’t know if you've seen, on packagist to install with composer, the command is “composer create-project” instead “composer require”

Kind regards

pchart

Unsupport full php 8.1

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"
},

increase radius of the position of Pie chart values

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 :

img_pie

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,

PHP 7.1: Uncaught Error: [] operator not supported for strings in (...)/vendor/szymach/c-pchart/src/BaseDraw.php on line 784

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:

c-pchart/src/BaseDraw.php

Lines 763 to 784 in 08a2937

$Width = "";
foreach ($Lines as $Key => $Value) {
$BoxArray = $this->getTextBox(
$vX + $IconAreaWidth + 6,
$Y + $IconAreaHeight / 2 + (($this->FontSize + 3) * $Key),
$FontName,
$FontSize,
0,
$Value
);
if ($Boundaries["T"] > $BoxArray[2]["Y"] + $IconAreaHeight / 2) {
$Boundaries["T"] = $BoxArray[2]["Y"] + $IconAreaHeight / 2;
}
if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) {
$Boundaries["R"] = $BoxArray[1]["X"] + 2;
}
if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $IconAreaHeight / 2) {
$Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $IconAreaHeight / 2;
}
$Width[] = $BoxArray[1]["X"];

Bubble labels are rendered in the wrong positions

When using method writeBubbleLabel for more than two values in the abscissa the points for the labels after the second value is computerd incorrectly. Attached is a rendered chart below for such a scenario

bubble_label

Licensing conundrum

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

Axis Name not set for the index 1

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

Loading palette not working in PHP 7.1

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".

PR on PHP 7.1 support

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?

The requested chart is not a seperate class for bar charts

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
`

Function drawLine() fails to heed setSerieWeight() if not anti-aliased nor setSerieTicks() used

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);
      }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.