PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,87 @@
# Drawing a 2D pie chart
[Reference](http://wiki.pchart.net/doc.pie.draw2dpie.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Pie;
// Create and populate data
$data = new Data();
$data->addPoints([40, 60, 15, 10, 6, 4], "ScoreA");
$data->setSerieDescription("ScoreA", "Application A");
// Define the absissa serie
$data->addPoints(["<10", "10<>20", "20<>40", "40<>60", "60<>80", ">80"], "Labels");
$data->setAbscissa("Labels");
// Create the image
$image = new Image(700, 230, $data);
// Draw a solid background
$backgroundSettings = [
"R" => 173,
"G" => 152,
"B" => 217,
"Dash" => 1,
"DashR" => 193,
"DashG" => 172,
"DashB" => 237
];
$image->drawFilledRectangle(0, 0, 700, 230, $backgroundSettings);
//Draw a gradient overlay
$gradientSettings = [
"StartR" => 209,
"StartG" => 150,
"StartB" => 231,
"EndR" => 111,
"EndG" => 3,
"EndB" => 138,
"Alpha" => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $gradientSettings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
// Add a border to the picture
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
// Write the picture title
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pPie - Draw 2D pie charts", ["R" => 255, "G" => 255, "B" => 255]);
// Set the default font properties
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
// Enable shadow computing
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 150, "G" => 150, "B" => 150, "Alpha" => 100]);
$image->drawText(140, 200, "Single AA pass", ["R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE]);
// Create and draw the chart
$pieChart = new Pie($image, $data);
$pieChart->draw2DPie(140, 125, ["SecondPass" => false]);
$pieChart->draw2DPie(340, 125, ["DrawLabels" => true, "Border" => true]);
$pieChart->draw2DPie(540, 125, [
"DataGapAngle" => 10,
"DataGapRadius" => 6,
"Border" => true,
"BorderR" => 255,
"BorderG" => 255,
"BorderB" => 255
]);
$image->drawText(540, 200, "Extended AA pass / Splitted", ["R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE]);
$pieChart->pChartObject->autoOutput("example.draw2DPie.png");
```

View File

@ -0,0 +1,72 @@
# Drawing a 2D ring chart
[Reference](http://wiki.pchart.net/doc.pie.draw2dring.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Pie;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], "ScoreA");
$data->setSerieDescription("ScoreA", "Application A");
/* Define the absissa serie */
$data->addPoints(["A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"], "Labels");
$data->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(300, 260, $data);
/* Draw a solid background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 300, 300, $settings);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 300, 260, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 300, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0,
"StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 299, 259, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pPie - Draw 2D ring charts", ["R" => 255, "G" => 255, "B" => 255]);
/* Set the default font properties */
$image->setFontProperties([
"FontName" => "Forgotte.ttf",
"FontSize" => 10,
"R" => 80,
"G" => 80,
"B" => 80
]);
/* Enable shadow computing */
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50]);
/* Create the pPie object */
$pieChart = new Pie($image, $data);
/* Draw an AA pie chart */
$pieChart->draw2DRing(160, 140, ["DrawLabels" => true, "LabelStacked" => true, "Border" => true]);
/* Write the legend box */
$image->setShadow(false);
$pieChart->drawPieLegend(15, 40, ["Alpha" => 20]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.draw2DRing.png");
```

View File

@ -0,0 +1,119 @@
# Drawing a 3D pie chart
[Reference](http://wiki.pchart.net/doc.pie.draw3dpie.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Pie;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([40, 30, 20], "ScoreA");
$data->setSerieDescription("ScoreA", "Application A");
/* Define the absissa serie */
$data->addPoints(["A", "B", "C"], "Labels");
$data->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(700, 230, $data, true);
/* Draw a solid background */
$image->drawFilledRectangle(0, 0, 700, 230, [
"R" => 173,
"G" => 152,
"B" => 217,
"Dash" => 1,
"DashR" => 193,
"DashG" => 172,
"DashB" => 237
]);
/* Draw a gradient overlay */
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, [
"StartR" => 209,
"StartG" => 150,
"StartB" => 231,
"EndR" => 111,
"EndG" => 3,
"EndB" => 138,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pPie - Draw 3D pie charts", ["R" => 255, "G" => 255,
"B" => 255]);
/* Set the default font properties */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10,
"R" => 80, "G" => 80, "B" => 80]);
/* Create the pPie object */
$pieChart = new Pie($image, $data);
/* Define the slice color */
$pieChart->setSliceColor(0, ["R" => 143, "G" => 197, "B" => 0]);
$pieChart->setSliceColor(1, ["R" => 97, "G" => 77, "B" => 63]);
$pieChart->setSliceColor(2, ["R" => 97, "G" => 113, "B" => 63]);
/* Draw a simple pie chart */
$pieChart->draw3DPie(120, 125, ["SecondPass" => false]);
/* Draw an AA pie chart */
$pieChart->draw3DPie(340, 125, ["DrawLabels" => true, "Border" => true]);
/* Enable shadow computing */
$image->setShadow(true, ["X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw a splitted pie chart */
$pieChart->draw3DPie(560, 125, ["WriteValues" => true, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => true]);
/* Write the legend */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
$image->drawText(120, 200, "Single AA pass", [
"DrawBox" => true,
"BoxRounded" => true,
"R" => 0,
"G" => 0,
"B" => 0,
"Align" => TEXT_ALIGN_TOPMIDDLE
]);
$image->drawText(440, 200, "Extended AA pass / Splitted", [
"DrawBox" => true,
"BoxRounded" => true,
"R" => 0,
"G" => 0,
"B" => 0,
"Align" => TEXT_ALIGN_TOPMIDDLE
]);
/* Write the legend box */
$image->setFontProperties([
"FontName" => "Silkscreen.ttf",
"FontSize" => 6,
"R" => 255,
"G" => 255,
"B" => 255
]);
$pieChart->drawPieLegend(600, 8, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.draw3DPie.png");
```

View File

@ -0,0 +1,78 @@
# Drawing a 3D ring chart
[Reference](http://wiki.pchart.net/doc.pie.draw3dring.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Pie;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], "ScoreA");
$data->setSerieDescription("ScoreA", "Application A");
/* Define the absissa serie */
$data->addPoints(["A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"], "Labels");
$data->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw a solid background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pPie - Draw 3D ring charts", ["R" => 255, "G" => 255, "B" => 255]);
/* Set the default font properties */
$image->setFontProperties([
"FontName" => "Forgotte.ttf",
"FontSize" => 10,
"R" => 80,
"G" => 80,
"B" => 80
]);
/* Enable shadow computing */
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50]);
/* Create the pPie object */
$pieChart = new Pie($image, $data);
/* Draw an AA pie chart */
$pieChart->draw3DRing(200, 200, ["DrawLabels" => true, "LabelStacked" => true, "Border" => true]);
/* Write the legend box */
$pieChart->drawPieLegend(80, 360, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER, "Alpha" => 20]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.draw3DRing.png");
```

View File

@ -0,0 +1,72 @@
# Drawing an area chart
[Reference](http://wiki.pchart.net/doc.chart.drawareachart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
$data = new Data();
for ($i = 0; $i <= 30; $i++) {
$data->addPoints(rand(1, 15), "Probe 1");
}
$data->setSerieTicks("Probe 2", 4);
$data->setAxisName(0, "Temperatures");
// Create the Image object
$image = new Image(700, 230, $data);
/* Turn off Antialiasing */
$image->Antialias = false;
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the chart title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(150, 35, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Define the chart area */
$image->setGraphArea(60, 40, 650, 200);
/* Draw the scale */
$scaleSettings = [
"XMargin" => 10,
"YMargin" => 10,
"Floating" => true,
"GridR" => 200,
"GridG" => 200,
"GridB" => 200,
"DrawSubTicks" => true,
"CycleBackground" => true
];
$image->drawScale($scaleSettings);
/* Write the chart legend */
$image->drawLegend(600, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Turn on Antialiasing */
$image->Antialias = true;
/* Enable shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw the area chart */
$Threshold = [];
$Threshold[] = ["Min" => 0, "Max" => 5, "R" => 207, "G" => 240, "B" => 20, "Alpha" => 70];
$Threshold[] = ["Min" => 5, "Max" => 10, "R" => 240, "G" => 232, "B" => 20, "Alpha" => 70];
$Threshold[] = ["Min" => 10, "Max" => 20, "R" => 240, "G" => 191, "B" => 20, "Alpha" => 70];
$image->drawAreaChart(["Threshold" => $Threshold]);
/* Write the thresholds */
$image->drawThreshold(5, ["WriteCaption" => true, "Caption" => "Warn Zone", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255]);
$image->drawThreshold(10, ["WriteCaption" => true, "Caption" => "Error Zone", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawAreaChart.threshold.png");
```

View File

@ -0,0 +1,64 @@
# Drawing a bar chart
[Reference](http://wiki.pchart.net/doc.chart.drawbarchart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([13251, 4118, 3087, 1460, 1248, 156, 26, 9, 8], "Hits");
$data->setAxisName(0, "Hits");
$data->addPoints(["Firefox", "Chrome", "Internet Explorer", "Opera", "Safari", "Mozilla", "SeaMonkey", "Camino", "Lunascape"], "Browsers");
$data->setSerieDescription("Browsers", "Browsers");
$data->setAbscissa("Browsers");
/* Create the Image object */
$image = new Image(500, 500, $data);
$image->drawGradientArea(0, 0, 500, 500, DIRECTION_VERTICAL, [
"StartR" => 240,
"StartG" => 240,
"StartB" => 240,
"EndR" => 180,
"EndG" => 180,
"EndB" => 180,
"Alpha" => 100
]);
$image->drawGradientArea(0, 0, 500, 500, DIRECTION_HORIZONTAL, [
"StartR" => 240,
"StartG" => 240,
"StartB" => 240,
"EndR" => 180,
"EndG" => 180,
"EndB" => 180,
"Alpha" => 20
]);
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Draw the chart scale */
$image->setGraphArea(100, 30, 480, 480);
$image->drawScale([
"CycleBackground" => true,
"DrawSubTicks" => true,
"GridR" => 0,
"GridG" => 0,
"GridB" => 0,
"GridAlpha" => 10,
"Pos" => SCALE_POS_TOPBOTTOM
]);
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw the chart */
$image->drawBarChart(["DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => true, "Rounded" => true, "Surrounding" => 30]);
/* Write the legend */
$image->drawLegend(570, 215, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawBarChart.vertical.png");
```

View File

@ -0,0 +1,89 @@
# Drawing a barcode 128
[Reference](http://wiki.pchart.net/doc.barcode128.pBarcode128.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Barcode128;
use CpChart\Chart\Image;
/* Create the Image object */
$image = new Image(700, 230);
/* Draw the background */
$image->drawFilledRectangle(0, 0, 700, 230, [
"R" => 170,
"G" => 183,
"B" => 87,
"Dash" => 1,
"DashR" => 190,
"DashG" => 203,
"DashB" => 107
]);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Draw the top bar */
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "Barcode 128 - Add barcode to your pictures", ["R" => 255, "G" => 255, "B" => 255]);
/* Create the barcode 128 object */
$barcodeChart = new Barcode128();
/* Draw a simple barcode */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$barcodeChart->draw($image, "pChart Rocks!", 50, 50, ["ShowLegend" => true, "DrawArea" => true]);
/* Draw a rotated barcode */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
$barcodeChart->draw($image, "Turn me on", 650, 50, ["ShowLegend" => true, "DrawArea" => true, "Angle" => 90]);
/* Draw a rotated barcode */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
$barcodeChart->draw($image, "Do what you want !", 290, 140, [
"R" => 255,
"G" => 255,
"B" => 255,
"AreaR" => 150,
"AreaG" => 30,
"AreaB" => 27,
"ShowLegend" => true,
"DrawArea" => true,
"Angle" => 350,
"AreaBorderR" => 70,
"AreaBorderG" => 20,
"AreaBorderB" => 20
]);
/* Render the picture */
$image->autoOutput("example.barcode128.png");
```

View File

@ -0,0 +1,82 @@
# Drawing a barcode 39
[Reference](http://wiki.pchart.net/doc.barcode39.pBarcode39.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Barcode39;
use CpChart\Chart\Image;
/* Create the Image object */
$image = new Image(700, 230);
/* Draw the background */
$image->drawFilledRectangle(0, 0, 700, 230, [
"R" => 170,
"G" => 183,
"B" => 87,
"Dash" => 1,
"DashR" => 190,
"DashG" => 203,
"DashB" => 107
]);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Draw the picture border */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "Barcode 39 - Add barcode to your pictures", ["R" => 255, "G" => 255, "B" => 255]);
/* Create the barcode 39 object */
$barcodeChart = new Barcode39();
/* Draw a simple barcode */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$barcodeChart->draw($image, "pChart Rocks!", 50, 50, ["ShowLegend" => true, "DrawArea" => true]);
/* Draw a rotated barcode */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
$barcodeChart->draw($image, "Turn me on", 650, 50, ["ShowLegend" => true, "DrawArea" => true, "Angle" => 90]);
/* Draw a rotated barcode */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
$barcodeChart->draw($image, "Do what you want !", 290, 140, [
"R" => 255,
"G" => 255,
"B" => 255,
"AreaR" => 150,
"AreaG" => 30,
"AreaB" => 27,
"ShowLegend" => true,
"DrawArea" => true,
"Angle" => 350,
"AreaBorderR" => 70,
"AreaBorderG" => 20,
"AreaBorderB" => 20
]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.barcode39.png");
```

View File

@ -0,0 +1,70 @@
# Drawing a best fit chart
[Reference](http://wiki.pchart.net/doc.chart.drawbestfit.html)
``` php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(10, 30) + $i, "Probe 1");
}
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(0, 10) + $i, "Probe 2");
}
$data->setAxisName(0, "Temperatures");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Turn off Antialiasing */
$image->Antialias = false;
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the chart title */
$image->setFontProperties(["FontName" => ".Forgotte.ttf", "FontSize" => 11]);
$image->drawText(150, 35, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Set the default font */
$image->setFontProperties(["FontName" => ".pf_arma_five.ttf", "FontSize" => 6]);
/* Define the chart area */
$image->setGraphArea(60, 40, 650, 200);
/* Draw the scale */
$scaleSettings = [
"XMargin" => 10,
"YMargin" => 10,
"Floating" => true,
"GridR" => 200,
"GridG" => 200,
"GridB" => 200,
"DrawSubTicks" => true,
"CycleBackground" => true
];
$image->drawScale($scaleSettings);
/* Turn on Antialiasing */
$image->Antialias = true;
/* Draw the line of best fit */
$image->drawBestFit();
/* Turn on shadows */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw the line chart */
$image->drawPlotChart();
/* Write the chart legend */
$image->drawLegend(580, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawBestFit.png");
```

View File

@ -0,0 +1,107 @@
# Drawing a linear bubble chart
[Reference](http://wiki.pchart.net/doc.bubble.drawbubblechart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Bubble;
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([34, 55, 15, 62, 38, 42], "Probe1");
$data->addPoints([5, 10, 8, 9, 15, 10], "Probe1Weight");
$data->addPoints([5, 10, -5, -1, 0, -10], "Probe2");
$data->addPoints([6, 10, 14, 10, 14, 6], "Probe2Weight");
$data->setSerieDescription("Probe1", "This year");
$data->setSerieDescription("Probe2", "Last year");
$data->setAxisName(0, "Current stock");
$data->addPoints(["Apple", "Banana", "Orange", "Lemon", "Peach", "Strawberry"], "Product");
$data->setAbscissa("Product");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawBubbleChart() - draw a linear bubble chart", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Write the title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(40, 55, "Current Stock / Needs chart", ["FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMLEFT]);
/* Change the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Create the Bubble chart object and scale up */
$bubbleChart = new Bubble($image, $data);
/* Scale up for the bubble chart */
$bubbleDataSeries = ["Probe1", "Probe2"];
$bubbleWeightSeries = ["Probe1Weight", "Probe2Weight"];
$bubbleChart->bubbleScale($bubbleDataSeries, $bubbleWeightSeries);
/* Draw the 1st chart */
$image->setGraphArea(40, 60, 430, 190);
$image->drawFilledRectangle(40, 60, 430, 190, ["R" => 255, "G" => 255, "B" => 255,
"Surrounding" => -200, "Alpha" => 10]);
$image->drawScale(["DrawSubTicks" => true, "CycleBackground" => true]);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
$bubbleChart->drawBubbleChart($bubbleDataSeries, $bubbleWeightSeries);
/* Draw the 2nd scale */
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(500, 60, 670, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
/* Draw the 2nd stock chart */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
$bubbleChart->drawbubbleChart($bubbleDataSeries, $bubbleWeightSeries);
/* Write the chart legend */
$image->drawLegend(550, 215, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawBubbleChart.png");
```

View File

@ -0,0 +1,83 @@
# Cache operations
[Reference](http://wiki.pchart.net/doc.pcache.pcache.html)
To speed up the process of creating charts, you can store them in the cache files
using the `CpChart\Chart\Cache` class. It will create two files - `cache.db` and
`index.db` in a dedicated directory (`app\cache` by default, relative to the library's
root directory), but you can change these using the `$settings` array passed
to the object's constructor.
Should you decide to use the cache component, the following sections describe
how you can do that.
## Using cache to store and retrieve chart data
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Cache;
use CpChart\Chart\Data;
use CpChart\Chart\Image;
// Standard chart creation
$data = new Data();
$data->addPoints([1, 3, 4, 3, 5]);
$image = new Image(700, 230, $data);
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->setGraphArea(60, 40, 670, 190);
$image->drawScale();
$image->drawSplineChart();
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "Test of the pCache class", ["R" => 255, "G" => 255, "B" => 255]);
// Create a cache object and store the chart in it
$cache = new Cache([
// Optionally change the default directory and file names
'CacheFolder' => 'path/to/your/cache/directory',
'CacheIndex' => 'name_of_the_index_file.db',
'CacheDB' => 'name_of_the_database_file.db'
]);
$chartHash = $cache->getHash($data); // Chart dentifier in the cache
$cache->writeToCache($chartHash, $image);
// Create an image file from cache
$cache->saveFromCache($chartHash, "example.drawCachedSpline.png");
// Directly stroke the saved data to the browser
$cache->strokeFromCache($chartHash)
// Automatically choose a way to output stored data
$cache->autoOutput($chartHash)
```
## Removal operations
```php
// Assuming we have $chartHash and $cache variables from the previous example
// This will remove the chart by it's hash
$cache->remove($chartHash);
// This will remove every chart in cache older than the amount of seconds passed
// into the argument's parameter
$cache->removeOlderThan(60 * 60 * 24); // Remove data older than 24 hours
// This flushes the cache completely and regenerates the .db files
$cache->flush();
```
There is also the function called `CpChart\Chart\Cache::dbRemoval(array $settings)`,
but it only covers two use cases - removing by chart hash and age. Since there
are dedicated methods for each of them (`remove` and `removeOlderThan`, respectively),
there is no reason to cover it any further.

View File

@ -0,0 +1,92 @@
# Drawing a contour chart
[Reference](http://wiki.pchart.net/doc.surface.drawcontour.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Surface;
/* Create the Image object */
$image = new Image(400, 400);
/* Create a solid background */
$image->drawFilledRectangle(0, 0, 400, 400, [
"R" => 179,
"G" => 217,
"B" => 91,
"Dash" => 1,
"DashR" => 199,
"DashG" => 237,
"DashB" => 111
]);
/* Do a gradient overlay */
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
"StartR" => 194,
"StartG" => 231,
"StartB" => 44,
"EndR" => 43,
"EndG" => 107,
"EndB" => 58,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pSurface() :: 2D surface charts", ["R" => 255, "G" => 255, "B" => 255]);
/* Define the charting area */
$image->setGraphArea(20, 40, 380, 380);
$image->drawFilledRectangle(20, 40, 380, 380, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 20
]);
$image->setShadow(true, ["X" => 1, "Y" => 1]);
/* Create the surface object */
$surfaceChart = new Surface($image);
/* Set the grid size */
$surfaceChart->setGrid(20, 20);
/* Write the axis labels */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$surfaceChart->writeXLabels(["Position" => LABEL_POSITION_BOTTOM]);
$surfaceChart->writeYLabels();
/* Add random values */
for ($i = 0; $i <= 50; $i++) {
$surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100));
}
/* Compute the missing points */
$surfaceChart->computeMissing();
/* Draw the surface chart */
$surfaceChart->drawSurface(["Border" => true, "Surrounding" => 40]);
/* Draw the contour with a threshold of 50 */
$surfaceChart->drawContour(50, ["R" => 0, "G" => 0, "B" => 0]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.surface.png");
```

View File

@ -0,0 +1,125 @@
# Drawing a filled spline chart
[Reference](http://wiki.pchart.net/doc.chart.drawFilledSplineChart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
$data->setAxisName(0, "Strength");
for ($i = 0; $i <= 720; $i = $i + 20) {
$data->addPoints(cos(deg2rad($i)) * 100, "Probe 1");
$data->addPoints(cos(deg2rad($i + 90)) * 60, "Probe 2");
}
/* Create the Image object */
$image = new Image(847, 304, $data);
$image->drawGradientArea(0, 0, 847, 304, DIRECTION_VERTICAL, [
"StartR" => 47,
"StartG" => 47,
"StartB" => 47,
"EndR" => 17,
"EndG" => 17,
"EndB" => 17,
"Alpha" => 100
]);
$image->drawGradientArea(0, 250, 847, 304, DIRECTION_VERTICAL, [
"StartR" => 47,
"StartG" => 47,
"StartB" => 47,
"EndR" => 27,
"EndG" => 27,
"EndB" => 27,
"Alpha" => 100
]);
$image->drawLine(0, 249, 847, 249, ["R" => 0, "G" => 0, "B" => 0]);
$image->drawLine(0, 250, 847, 250, ["R" => 70, "G" => 70, "B" => 70]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 846, 303, ["R" => 204, "G" => 204, "B" => 204]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->drawText(423, 14, "Cyclic magnetic field strength", [
"R" => 255,
"G" => 255,
"B" => 255,
"Align" => TEXT_ALIGN_MIDDLEMIDDLE
]);
/* Define the chart area */
$image->setGraphArea(58, 27, 816, 228);
/* Draw a rectangle */
$image->drawFilledRectangle(58, 27, 816, 228, [
"R" => 0,
"G" => 0,
"B" => 0,
"Dash" => true,
"DashR" => 0,
"DashG" => 51,
"DashB" => 51,
"BorderR" => 0,
"BorderG" => 0,
"BorderB" => 0
]);
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
/* Draw the scale */
$image->setFontProperties(["R" => 255, "G" => 255, "B" => 255]);
$ScaleSettings = [
"XMargin" => 4,
"DrawSubTicks" => true,
"GridR" => 255,
"GridG" => 255,
"GridB" => 255,
"AxisR" => 255,
"AxisG" => 255,
"AxisB" => 255,
"GridAlpha" => 30,
"CycleBackground" => true
];
$image->drawScale($ScaleSettings);
/* Draw the spline chart */
$image->drawFilledSplineChart();
/* Write the chart boundaries */
$BoundsSettings = [
"MaxDisplayR" => 237,
"MaxDisplayG" => 23,
"MaxDisplayB" => 48,
"MinDisplayR" => 23,
"MinDisplayG" => 144,
"MinDisplayB" => 237
];
$image->writeBounds(BOUND_BOTH, $BoundsSettings);
/* Write the 0 line */
$image->drawThreshold(0, ["WriteCaption" => true]);
/* Write the chart legend */
$image->setFontProperties(["R" => 255, "G" => 255, "B" => 255]);
$image->drawLegend(560, 266, ["Style" => LEGEND_NOBORDER]);
/* Write the 1st data series statistics */
$settings = ["R" => 188, "G" => 224, "B" => 46, "Align" => TEXT_ALIGN_BOTTOMLEFT];
$image->drawText(620, 270, "Max : " . ceil($data->getMax("Probe 1")), $settings);
$image->drawText(680, 270, "Min : " . ceil($data->getMin("Probe 1")), $settings);
$image->drawText(740, 270, "Avg : " . ceil($data->getSerieAverage("Probe 1")), $settings);
/* Write the 2nd data series statistics */
$settings = ["R" => 224, "G" => 100, "B" => 46, "Align" => TEXT_ALIGN_BOTTOMLEFT];
$image->drawText(620, 283, "Max : " . ceil($data->getMax("Probe 2")), $settings);
$image->drawText(680, 283, "Min : " . ceil($data->getMin("Probe 2")), $settings);
$image->drawText(740, 283, "Avg : " . ceil($data->getSerieAverage("Probe 2")), $settings);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawFilledSplineChart.png");
```

View File

@ -0,0 +1,75 @@
# Drawing a filled step chart
[Reference](http://wiki.pchart.net/doc.chart.drawfilledstepchart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([-4, 2, VOID, 12, 8, 3], "Probe 1");
$data->addPoints([3, 12, 15, 8, 5, -5], "Probe 2");
$data->addPoints([2, 7, 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->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawFilledStepChart() - draw a filled step chart", ["R" => 255, "G" => 255, "B" => 255]);
/* Write the chart title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(250, 55, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Draw the scale and the 1st chart */
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(60, 60, 450, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
$image->drawScale(["DrawSubTicks" => true]);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->drawFilledStepChart(["ForceTransparency" => 40, "DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO]);
$image->setShadow(false);
/* Draw the scale and the 2nd chart */
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(500, 60, 670, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
$image->setShadow(true, ["X" => -1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$image->drawFilledStepChart(["ForceTransparency" => 40]);
$image->setShadow(false);
/* Write the chart legend */
$image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawFilledStepChart.png");
```

View File

@ -0,0 +1,50 @@
# Drawing a line chart
[Reference](http://wiki.pchart.net/doc.chart.drawlinechart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Build a dataset */
$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, 7, 5, 18, 19, 22], "Probe 3");
$data->setSerieTicks("Probe 2", 4);
$data->setSerieWeight("Probe 3", 2);
$data->setAxisName(0, "Temperatures");
$data->addPoints(["Jan", "Feb", "Mar", "Apr", "May", "Jun"], "Labels");
$data->setSerieDescription("Labels", "Months");
$data->setAbscissa("Labels");
/* Create the 1st chart */
$image = new Image(700, 230, $data);
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(60, 60, 450, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["DrawSubTicks" => true]);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$image->setFontProperties(["FontName" => "fonts/pf_arma_five.ttf", "FontSize" => 6]);
$image->drawLineChart(["DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO]);
$image->setShadow(false);
/* Create the 2nd chart */
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(500, 60, 670, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
$image->setShadow(true, ["X" => -1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$image->drawLineChart();
$image->setShadow(false);
/* Write the legend */
$image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
$image->autoOutput("example.drawLineChart.png");
```

View File

@ -0,0 +1,67 @@
# Drawing a plot chart
[Reference](http://wiki.pchart.net/doc.chart.drawplotchart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(0, 20), "Probe 1");
}
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(0, 20), "Probe 2");
}
$data->setSerieShape("Probe 1", SERIE_SHAPE_FILLEDTRIANGLE);
$data->setSerieShape("Probe 2", SERIE_SHAPE_FILLEDSQUARE);
$data->setAxisName(0, "Temperatures");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Turn off Antialiasing */
$image->Antialias = false;
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the chart title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(150, 35, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Define the chart area */
$image->setGraphArea(60, 40, 650, 200);
/* Draw the scale */
$scaleSettings = [
"XMargin" => 10,
"YMargin" => 10,
"Floating" => true,
"GridR" => 200,
"GridG" => 200,
"GridB" => 200,
"DrawSubTicks" => true,
"CycleBackground" => true
];
$image->drawScale($scaleSettings);
/* Turn on Antialiasing */
$image->Antialias = true;
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw the line chart */
$image->drawPlotChart();
/* Write the chart legend */
$image->drawLegend(580, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawPlotChart.simple.png");
```

View File

@ -0,0 +1,96 @@
# Drawing a polar chart
[Reference](http://wiki.pchart.net/doc.draw.polar.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Radar;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([10, 20, 30, 40, 50, 60, 70, 80, 90], "ScoreA");
$data->addPoints([20, 40, 50, 12, 10, 30, 40, 50, 60], "ScoreB");
$data->setSerieDescription("ScoreA", "Coverage A");
$data->setSerieDescription("ScoreB", "Coverage B");
/* Define the absissa serie */
$data->addPoints([40, 80, 120, 160, 200, 240, 280, 320, 360], "Coord");
$data->setAbscissa("Coord");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw a solid background */
$settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay some gradient areas */
$settings = ["StartR" => 194, "StartG" => 231, "StartB" => 44, "EndR" => 43, "EndG" => 107, "EndB" => 58, "Alpha" => 50];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pRadar - Draw polar charts", ["R" => 255, "G" => 255,
"B" => 255]);
/* Set the default font properties */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10,
"R" => 80, "G" => 80, "B" => 80]);
/* Enable shadow computing */
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0,
"Alpha" => 10]);
/* Create the pRadar object */
$radarChart = new Radar();
/* Draw a polar chart */
$image->setGraphArea(10, 25, 340, 225);
$options = ["BackgroundGradient" => [
"StartR" => 255,
"StartG" => 255,
"StartB" => 255,
"StartAlpha" => 100,
"EndR" => 207,
"EndG" => 227,
"EndB" => 125,
"EndAlpha" => 50
]];
$radarChart->drawPolar($image, $data, $options);
/* Draw a polar chart */
$image->setGraphArea(350, 25, 690, 225);
$options = [
"LabelPos" => RADAR_LABELS_HORIZONTAL,
"BackgroundGradient" => [
"StartR" => 255, "StartG" => 255, "StartB" => 255, "StartAlpha" => 50, "EndR" => 32,
"EndG" => 109, "EndB" => 174, "EndAlpha" => 30
],
"AxisRotation" => 0,
"DrawPoly" => true,
"PolyAlpha" => 50
];
$radarChart->drawPolar($image, $data, $options);
/* Write the chart legend */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->drawLegend(270, 205, ["Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.polar.png");
```

View File

@ -0,0 +1,71 @@
# Drawing a progress chart
[Reference](http://wiki.pchart.net/doc.chart.drawprogress.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
$image = new Image(700, 250);
/* Enable shadow support */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
/* Left Red bar */
$progressOptions = ["R" => 209, "G" => 31, "B" => 27, "Surrounding" => 20, "BoxBorderR" => 0,
"BoxBorderG" => 0, "BoxBorderB" => 0, "BoxBackR" => 255, "BoxBackG" => 255, "BoxBackB" => 255,
"RFade" => 206, "GFade" => 133, "BFade" => 30, "ShowLabel" => true];
$image->drawProgress(40, 60, 77, $progressOptions);
/* Left Orange bar */
$progressOptions = ["Width" => 165, "R" => 209, "G" => 125, "B" => 27, "Surrounding" => 20,
"BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0, "BoxBackR" => 255, "BoxBackG" => 255,
"BoxBackB" => 255, "NoAngle" => true, "ShowLabel" => true, "LabelPos" => LABEL_POS_RIGHT];
$image->drawProgress(40, 100, 50, $progressOptions);
/* Left Yellow bar */
$progressOptions = ["Width" => 165, "R" => 209, "G" => 198, "B" => 27, "Surrounding" => 20,
"BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0, "BoxBackR" => 255, "BoxBackG" => 255,
"BoxBackB" => 255, "ShowLabel" => true, "LabelPos" => LABEL_POS_LEFT];
$image->drawProgress(75, 140, 25, $progressOptions);
/* Left Green bar */
$progressOptions = ["Width" => 400, "R" => 134, "G" => 209, "B" => 27, "Surrounding" => 20,
"BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0, "BoxBackR" => 255, "BoxBackG" => 255,
"BoxBackB" => 255, "RFade" => 206, "GFade" => 133, "BFade" => 30, "ShowLabel" => true,
"LabelPos" => LABEL_POS_CENTER];
$image->drawProgress(40, 180, 80, $progressOptions);
/* Right vertical Red bar */
$progressOptions = ["Width" => 20, "Height" => 150, "R" => 209, "G" => 31, "B" => 27,
"Surrounding" => 20, "BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0,
"BoxBackR" => 255, "BoxBackG" => 255, "BoxBackB" => 255, "RFade" => 206, "GFade" => 133,
"BFade" => 30, "ShowLabel" => true, "Orientation" => ORIENTATION_VERTICAL, "LabelPos" => LABEL_POS_BOTTOM];
$image->drawProgress(500, 200, 77, $progressOptions);
/* Right vertical Orange bar */
$progressOptions = ["Width" => 20, "Height" => 150, "R" => 209, "G" => 125,
"B" => 27, "Surrounding" => 20, "BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0,
"BoxBackR" => 255, "BoxBackG" => 255, "BoxBackB" => 255, "NoAngle" => true, "ShowLabel" => true,
"Orientation" => ORIENTATION_VERTICAL, "LabelPos" => LABEL_POS_TOP];
$image->drawProgress(540, 200, 50, $progressOptions);
/* Right vertical Yellow bar */
$progressOptions = ["Width" => 20, "Height" => 150, "R" => 209, "G" => 198,
"B" => 27, "Surrounding" => 20, "BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0,
"BoxBackR" => 255, "BoxBackG" => 255, "BoxBackB" => 255, "ShowLabel" => true,
"Orientation" => ORIENTATION_VERTICAL, "LabelPos" => LABEL_POS_INSIDE];
$image->drawProgress(580, 200, 25, $progressOptions);
/* Right vertical Green bar */
$progressOptions = ["Width" => 20, "Height" => 150, "R" => 134, "G" => 209,
"B" => 27, "Surrounding" => 20, "BoxBorderR" => 0, "BoxBorderG" => 0, "BoxBorderB" => 0,
"BoxBackR" => 255, "BoxBackG" => 255, "BoxBackB" => 255, "RFade" => 206, "GFade" => 133,
"BFade" => 30, "ShowLabel" => true, "Orientation" => ORIENTATION_VERTICAL, "LabelPos" => LABEL_POS_CENTER];
$image->drawProgress(620, 200, 80, $progressOptions);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawProgressChart.png");
```

View File

@ -0,0 +1,98 @@
# Drawing a radar chart
[Reference](http://wiki.pchart.net/doc.draw.radar.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Radar;
/* Prepare some nice data & axis config */
$data = new Data();
$data->addPoints([40, 20, 15, 10, 8, 4], "ScoreA");
$data->addPoints([8, 10, 12, 20, 30, 15], "ScoreB");
$data->setSerieDescription("ScoreA", "Application A");
$data->setSerieDescription("ScoreB", "Application B");
/* Create the X serie */
$data->addPoints(["Size", "Speed", "Reliability", "Functionalities", "Ease of use", "Weight"], "Labels");
$data->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw a solid background */
$settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay some gradient areas */
$settings = ["StartR" => 194, "StartG" => 231, "StartB" => 44, "EndR" => 43, "EndG" => 107, "EndB" => 58, "Alpha" => 50];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
/* Draw the border */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pRadar - Draw radar charts", ["R" => 255, "G" => 255,
"B" => 255]);
/* Define general drawing parameters */
$image->setFontProperties([
"FontName" => "Forgotte.ttf",
"FontSize" => 10,
"R" => 80,
"G" => 80,
"B" => 80
]);
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Create the radar object */
$radarChart = new Radar();
/* Draw the 1st radar chart */
$image->setGraphArea(10, 25, 340, 225);
$Options = ["Layout" => RADAR_LAYOUT_STAR, "BackgroundGradient" => [
"StartR" => 255,
"StartG" => 255,
"StartB" => 255,
"StartAlpha" => 100,
"EndR" => 207,
"EndG" => 227,
"EndB" => 125,
"EndAlpha" => 50
]];
$radarChart->drawRadar($image, $data, $Options);
/* Draw the 2nd radar chart */
$image->setGraphArea(350, 25, 690, 225);
$Options = ["Layout" => RADAR_LAYOUT_CIRCLE, "LabelPos" => RADAR_LABELS_HORIZONTAL, "BackgroundGradient" => [
"StartR" => 255,
"StartG" => 255,
"StartB" => 255,
"StartAlpha" => 50,
"EndR" => 32,
"EndG" => 109,
"EndB" => 174,
"EndAlpha" => 30
]];
$radarChart->drawRadar($image, $data, $Options);
/* Write down the legend */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->drawLegend(270, 205, ["Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture */
$image->render("drawRadar.png");
```

View File

@ -0,0 +1,108 @@
# Drawing a scatter best fit chart
[Reference](http://wiki.pchart.net/doc.scatter.drawscatterbestfit.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Scatter;
/* Create the Data object */
$data = new Data();
/* Create the X axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(rand(1, 20) * 10 + rand(0, $i), "Probe 1");
}
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(rand(1, 2) * 10 + rand(0, $i), "Probe 2");
}
$data->setAxisName(0, "X-Index");
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_TOP);
/* Create the Y axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints($i, "Probe 3");
}
$data->setSerieOnAxis("Probe 3", 1);
$data->setAxisName(1, "Y-Index");
$data->setAxisXY(1, AXIS_Y);
$data->setAxisPosition(1, AXIS_POSITION_LEFT);
/* Create the 1st scatter chart binding */
$data->setScatterSerie("Probe 1", "Probe 3", 0);
$data->setScatterSerieDescription(0, "This year");
$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
/* Create the 2nd scatter chart binding */
$data->setScatterSerie("Probe 2", "Probe 3", 1);
$data->setScatterSerieDescription(1, "Last Year");
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawScatterBestFit() - Linear regression", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Set the graph area */
$image->setGraphArea(50, 60, 350, 360);
/* Create the Scatter chart object */
$myScatter = new Scatter($image, $data);
/* Draw the scale */
$myScatter->drawScatterScale();
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw a scatter plot chart */
$myScatter->drawScatterPlotChart();
/* Draw the legend */
$myScatter->drawScatterLegend(280, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
/* Draw the line of best fit */
$myScatter->drawScatterBestFit();
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawScatterBestFit.png");
```

View File

@ -0,0 +1,100 @@
# Drawing a scatter line chart
[Reference](http://wiki.pchart.net/doc.scatter.drawscatterlineChart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Scatter;
/* Create the Data object */
$data = new Data();
/* Create the X axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(cos(deg2rad($i)) * 20, "Probe 1");
}
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(sin(deg2rad($i)) * 20, "Probe 2");
}
$data->setAxisName(0, "Index");
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
/* Create the Y axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints($i, "Probe 3");
}
$data->setSerieOnAxis("Probe 3", 1);
$data->setAxisName(1, "Degree");
$data->setAxisXY(1, AXIS_Y);
$data->setAxisUnit(1, "°");
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
/* Create the 1st scatter chart binding */
$data->setScatterSerie("Probe 1", "Probe 3", 0);
$data->setScatterSerieDescription(0, "This year");
$data->setScatterSerieTicks(0, 4);
$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
/* Create the 2nd scatter chart binding */
$data->setScatterSerie("Probe 2", "Probe 3", 1);
$data->setScatterSerieDescription(1, "Last Year");
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawScatterLineChart() - Draw a scatter line chart", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Set the graph area */
$image->setGraphArea(50, 50, 350, 350);
/* Create the Scatter chart object */
$myScatter = new Scatter($image, $data);
/* Draw the scale */
$myScatter->drawScatterScale();
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw a scatter plot chart */
$myScatter->drawScatterLineChart();
/* Draw the legend */
$myScatter->drawScatterLegend(280, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawScatterLineChart.png");
```

View File

@ -0,0 +1,107 @@
# Drawing a scatter plot chart
[Reference](http://wiki.pchart.net/doc.scatter.drawscatterplotChart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Scatter;
/* Create the Data object */
$data = new Data();
/* Create the X axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(cos(deg2rad($i)) * 20, "Probe 1");
}
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(sin(deg2rad($i)) * 20, "Probe 2");
}
$data->setAxisName(0, "Index");
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
/* Create the Y axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints($i, "Probe 3");
}
$data->setSerieOnAxis("Probe 3", 1);
$data->setAxisName(1, "Degree");
$data->setAxisXY(1, AXIS_Y);
$data->setAxisUnit(1, "°");
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
/* Create the 1st scatter chart binding */
$data->setScatterSerie("Probe 1", "Probe 3", 0);
$data->setScatterSerieDescription(0, "This year");
$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
/* Create the 2nd scatter chart binding */
$data->setScatterSerie("Probe 2", "Probe 3", 1);
$data->setScatterSerieDescription(1, "Last Year");
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$settings = [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawScatterPlotChart() - Draw a scatter plot chart", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Set the graph area */
$image->setGraphArea(50, 50, 350, 350);
/* Create the Scatter chart object */
$myScatter = new Scatter($image, $data);
/* Draw the scale */
$myScatter->drawScatterScale();
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw a scatter plot chart */
$myScatter->drawScatterPlotChart();
/* Draw the legend */
$myScatter->drawScatterLegend(260, 375, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawScatterPlotChart.png");
```

View File

@ -0,0 +1,108 @@
# Drawing a scatter spline chart
[Reference](http://wiki.pchart.net/doc.scatter.drawscattersplineChart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Scatter;
/* Create the Data object */
$data = new Data();
/* Create the X axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 90) {
$data->addPoints(rand(1, 30), "Probe 1");
}
for ($i = 0; $i <= 360; $i = $i + 90) {
$data->addPoints(rand(1, 30), "Probe 2");
}
$data->setAxisName(0, "Index");
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
/* Create the Y axis and the binded series */
for ($i = 0; $i <= 360; $i = $i + 90) {
$data->addPoints($i, "Probe 3");
}
$data->setSerieOnAxis("Probe 3", 1);
$data->setAxisName(1, "Degree");
$data->setAxisXY(1, AXIS_Y);
$data->setAxisUnit(1, "°");
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
/* Create the 1st scatter chart binding */
$data->setScatterSerie("Probe 1", "Probe 3", 0);
$data->setScatterSerieDescription(0, "This year");
$data->setScatterSerieTicks(0, 4);
$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
/* Create the 2nd scatter chart binding */
$data->setScatterSerie("Probe 2", "Probe 3", 1);
$data->setScatterSerieDescription(1, "Last Year");
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$settings = [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawScatterSplineChart() - Draw a scatter spline chart", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Set the graph area */
$image->setGraphArea(50, 50, 350, 350);
/* Create the Scatter chart object */
$myScatter = new Scatter($image, $data);
/* Draw the scale */
$myScatter->drawScatterScale();
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw a scatter plot chart */
$myScatter->drawScatterSplineChart();
$myScatter->drawScatterPlotChart();
/* Draw the legend */
$myScatter->drawScatterLegend(280, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawScatterSplineChart.png");
```

View File

@ -0,0 +1,116 @@
# Drawing a scatter threshold chart
[Reference](http://wiki.pchart.net/doc.scatter.drawscatterthreshold.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Scatter;
/* Create the Data object */
$data = new Data();
/* Create the X axis and the binded series */
$data->createFunctionSerie("X", "1/z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
$data->setAxisName(0, "x = 1/z");
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
/* Create the Y axis */
$data->createFunctionSerie("Y", "z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
$data->setSerieOnAxis("Y", 1);
$data->setAxisName(1, "y = z");
$data->setAxisXY(1, AXIS_Y);
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
/* Create the Y axis */
$data->createFunctionSerie("Y2", "z*z*z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
$data->setSerieOnAxis("Y2", 2);
$data->setAxisName(2, "y = z*z*z");
$data->setAxisXY(2, AXIS_Y);
$data->setAxisPosition(2, AXIS_POSITION_LEFT);
/* Create the 1st scatter chart binding */
$data->setScatterSerie("X", "Y", 0);
$data->setScatterSerieDescription(0, "Pass A");
$data->setScatterSerieTicks(0, 4);
$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
/* Create the 2nd scatter chart binding */
$data->setScatterSerie("X", "Y2", 1);
$data->setScatterSerieDescription(1, "Pass B");
$data->setScatterSerieTicks(1, 4);
$data->setScatterSerieColor(1, ["R" => 120, "G" => 0, "B" => 255]);
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "createFunctionSerie() - Functions computing", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Set the graph area */
$image->setGraphArea(50, 50, 350, 350);
/* Create the Scatter chart object */
$myScatter = new Scatter($image, $data);
/* Draw the scale */
$myScatter->drawScatterScale(["XMargin" => 10, "YMargin" => 10, "Floating" => true]);
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw the 0/0 lines */
$myScatter->drawScatterThreshold(0, ["AxisID" => 0, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 10]);
$myScatter->drawScatterThreshold(0, ["AxisID" => 1, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 10]);
/* Draw a treshold area */
$myScatter->drawScatterThresholdArea(-0.1, 0.1, ["AreaName" => "Error zone"]);
/* Draw a scatter plot chart */
$myScatter->drawScatterLineChart();
$myScatter->drawScatterPlotChart();
/* Draw the legend */
$myScatter->drawScatterLegend(300, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.createFunctionSerie.scatter.png");
```

View File

@ -0,0 +1,116 @@
# Drawing a scatter threshold area chart
[Reference](http://wiki.pchart.net/doc.scatter.drawscatterthresholdarea.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Scatter;
/* Create the Data object */
$data = new Data();
/* Create the X axis and the binded series */
$data->createFunctionSerie("X", "1/z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
$data->setAxisName(0, "x = 1/z");
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
/* Create the Y axis */
$data->createFunctionSerie("Y", "z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
$data->setSerieOnAxis("Y", 1);
$data->setAxisName(1, "y = z");
$data->setAxisXY(1, AXIS_Y);
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
/* Create the Y axis */
$data->createFunctionSerie("Y2", "z*z*z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
$data->setSerieOnAxis("Y2", 2);
$data->setAxisName(2, "y = z*z*z");
$data->setAxisXY(2, AXIS_Y);
$data->setAxisPosition(2, AXIS_POSITION_LEFT);
/* Create the 1st scatter chart binding */
$data->setScatterSerie("X", "Y", 0);
$data->setScatterSerieDescription(0, "Pass A");
$data->setScatterSerieTicks(0, 4);
$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
/* Create the 2nd scatter chart binding */
$data->setScatterSerie("X", "Y2", 1);
$data->setScatterSerieDescription(1, "Pass B");
$data->setScatterSerieTicks(1, 4);
$data->setScatterSerieColor(1, ["R" => 120, "G" => 0, "B" => 255]);
/* Create the Image object */
$image = new Image(400, 400, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
/* Overlay with a gradient */
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "createFunctionSerie() - Functions computing", [
"R" => 255,
"G" => 255,
"B" => 255
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Set the graph area */
$image->setGraphArea(50, 50, 350, 350);
/* Create the Scatter chart object */
$myScatter = new Scatter($image, $data);
/* Draw the scale */
$myScatter->drawScatterScale(["XMargin" => 10, "YMargin" => 10, "Floating" => true]);
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw the 0/0 lines */
$myScatter->drawScatterThreshold(0, ["AxisID" => 0, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 10]);
$myScatter->drawScatterThreshold(0, ["AxisID" => 1, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 10]);
/* Draw a treshold area */
$myScatter->drawScatterThresholdArea(-0.1, 0.1, ["AreaName" => "Error zone"]);
/* Draw a scatter plot chart */
$myScatter->drawScatterLineChart();
$myScatter->drawScatterPlotChart();
/* Draw the legend */
$myScatter->drawScatterLegend(300, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.createFunctionSerie.scatter.png");
```

View File

@ -0,0 +1,37 @@
# Drawing a spline chart
[Reference](http://wiki.pchart.net/doc.chart.drawsplinechart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
// Create and populate data
$data = new Data();
$data->addPoints([], "Serie1")
// Create the image and set the data
$image = $factory->newImage(700, 230, $data);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
// 1st spline drawn in white with control points visible
$firstCoordinates = [[40, 80], [280, 60], [340, 166], [590, 120]];
$fistSplineSettings = ["R" => 255, "G" => 255, "B" => 255, "ShowControl" => true];
$image->drawSpline($firstCoordinates, $fistSplineSettings);
// 2nd spline dashed drawn in white with control points visible
$secondCoordinates = [[250, 50], [250, 180], [350, 180], [350, 50]];
$secondSplineSettings = [
"R" => 255,
"G" => 255,
"B"=> 255,
"ShowControl" => true,
"Ticks" => 4
];
$image->drawSpline($secondCoordinates, $secondSplineSettings);
// Render the picture (choose the best way)
$image->autoOutput("example.drawSpline.png");
```

View File

@ -0,0 +1,74 @@
# Drawing a split path chart
[Reference](http://wiki.pchart.net/doc.chart.drawsplitpath.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Split;
/* Create the Image object */
$data = new Image(700, 230);
/* Draw the background */
$settings = [
"R" => 170,
"G" => 183,
"B" => 87,
"Dash" => 1,
"DashR" => 190,
"DashG" => 203,
"DashB" => 107
];
$data->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1,
"EndG" => 138, "EndB" => 68, "Alpha" => 50];
$data->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$data->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0,
"StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
/* Add a border to the picture */
$data->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$data->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$data->drawText(10, 13, "pSplit - Draw splitted path charts", ["R" => 255, "G" => 255, "B" => 255]);
/* Set the default font properties */
$data->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
/* Enable shadow computing */
$data->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([30, 20, 15, 10, 8, 4], "Score");
$data->addPoints(["End of visit", "Home Page", "Product Page", "Sales", "Statistics", "Prints"], "Labels");
$data->setAbscissa("Labels");
/* Create the pSplit object */
$splitChart = new Split();
/* Draw the split chart */
$settings = ["TextPos" => TEXT_POS_RIGHT, "TextPadding" => 10, "Spacing" => 20, "Surrounding" => 40];
$data->setGraphArea(10, 20, 340, 230);
$splitChart->drawSplitPath($data, $data, $settings);
/* Create and populate the Data object */
$data2 = new Data();
$data2->addPoints([30, 20, 15], "Score");
$data2->addPoints(["UK", "FR", "ES"], "Labels");
$data2->setAbscissa("Labels");
/* Draw the split chart */
$settings = ["TextPadding" => 4, "Spacing" => 30, "Surrounding" => 20];
$data->setGraphArea(350, 50, 690, 200);
$splitChart->drawSplitPath($data, $data2, $settings);
/* Render the picture (choose the best way) */
$data->autoOutput("example.split.png");
```

View File

@ -0,0 +1,62 @@
# Drawing a spring chart
[Reference](http://wiki.pchart.net/doc.spring.drawspring.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Image;
use CpChart\Chart\Spring;
/* Create the Image object */
$image = new Image(300, 300);
/* Background customization */
$image->drawGradientArea(0, 0, 300, 300, DIRECTION_HORIZONTAL, [
"StartR" => 217,
"StartG" => 250,
"StartB" => 116,
"EndR" => 181,
"EndG" => 209,
"EndB" => 27,
"Alpha" => 100
]);
$image->drawGradientArea(0, 0, 300, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
$image->drawRectangle(0, 0, 299, 299, ["R" => 0, "G" => 0, "B" => 0]);
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pSpring - Draw spring charts", ["R" => 255, "G" => 255, "B" => 255]);
/* Prepare the graph area */
$image->setGraphArea(20, 20, 280, 280);
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 9, "R" => 80, "G" => 80, "B" => 80]);
$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Create the pSpring object */
$springChart = new Spring();
/* Set the nodes default settings */
$springChart->setNodeDefaults(["FreeZone" => 50]);
/* Build random nodes & connections */
for ($i = 0; $i <= 10; $i++) {
$connections = [];
for ($j = 0; $j <= rand(0, 1); $j++) {
$connections[] = rand(0, 10);
}
$springChart->addNode($i, ["Name" => "Node " . $i, "Connections" => $connections]);
}
/* Compute and draw the Spring Graph */
$springChart->drawSpring($image, ["DrawQuietZone" => true]);
/* Render the picture */
$image->render("drawSpring3.png");
```

View File

@ -0,0 +1,88 @@
# Drawing a stacked area chart
[Reference](http://wiki.pchart.net/doc.chart.drawstackedareachart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([1, -2, -1, 2, 1, 0], "Probe 1");
$data->addPoints([1, -2, -3, 2, 1, 8], "Probe 2");
$data->addPoints([2, 4, 2, 0, 4, 2], "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->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawStackedAreaChart() - draw a stacked area chart", ["R" => 255, "G" => 255, "B" => 255]);
/* Write the chart title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(250, 55, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Draw the scale and the 1st chart */
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(60, 60, 450, 190, ["R" => 255, "G" => 255, "B" => 255,
"Surrounding" => -200, "Alpha" => 10]);
$image->drawScale(["DrawSubTicks" => true, "Mode" => SCALE_MODE_ADDALL]);
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->setShadow(false);
$image->drawStackedAreaChart(["DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO, "Surrounding" => 20]);
/* Draw the scale and the 2nd chart */
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(500, 60, 670, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "Mode" => SCALE_MODE_ADDALL, "DrawSubTicks" => true]);
$image->setShadow(false);
$image->drawStackedAreaChart(["Surrounding" => 10]);
/* Write the chart legend */
$image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawStackedAreaChart.png");
```

View File

@ -0,0 +1,87 @@
# Drawing a stacked bar chart
[Reference](http://wiki.pchart.net/doc.chart.drawstackedbarchart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([-7, -8, -15, -20, -18, -12, 8, -19, 9, 16, -20, 8, 10, -10, -14, -20, 8, -9, -19], "Probe 3");
$data->addPoints([19, 0, -8, 8, -8, 12, -19, -10, 5, 12, -20, -8, 10, -11, -12, 8, -17, -14, 0], "Probe 4");
$data->setAxisName(0, "Temperatures");
$data->addPoints([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], "Time");
$data->setSerieDescription("Time", "Hour of the day");
$data->setAbscissa("Time");
$data->setXAxisUnit("h");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw the background */
$settings = [
"R" => 170,
"G" => 183,
"B" => 87,
"Dash" => 1,
"DashR" => 190,
"DashG" => 203,
"DashB" => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138,
"EndB" => 68,
"Alpha" => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
/* Set the default font properties */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Draw the scale */
$image->setGraphArea(60, 30, 650, 190);
$image->drawScale([
"CycleBackground" => true,
"DrawSubTicks" => true,
"GridR" => 0,
"GridG" => 0,
"GridB" => 0,
"GridAlpha" => 10,
"Mode" => SCALE_MODE_ADDALL
]);
/* Turn on shadow computing */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* Draw some thresholds */
$image->setShadow(false);
$image->drawThreshold(-40, ["WriteCaption" => true, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 4]);
$image->drawThreshold(28, ["WriteCaption" => true, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 4]);
/* Draw the chart */
$image->drawStackedBarChart([
"Rounded" => true,
"DisplayValues" => true,
"DisplayColor" => DISPLAY_AUTO,
"DisplaySize" => 6,
"BorderR" => 255,
"BorderG" => 255,
"BorderB" => 255
]);
/* Write the chart legend */
$image->drawLegend(570, 212, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawStackedBarChart.rounded.png");
```

View File

@ -0,0 +1,93 @@
# Drawing a step chart
[Reference](http://wiki.pchart.net/doc.chart.drawstepchart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$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, 7, 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->setAbscissa("Labels");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = [
"StartR" => 219,
"StartG" => 231,
"StartB" => 139,
"EndR" => 1,
"EndG" => 138, "EndB" => 68, "Alpha" => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 80
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "drawStepChart() - draw a step chart", ["R" => 255, "G" => 255, "B" => 255]);
/* Write the chart title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(250, 55, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Draw the scale and the 1st chart */
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(60, 60, 450, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["DrawSubTicks" => true]);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$image->drawStepChart(["DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO]);
$image->setShadow(false);
/* Draw the scale and the 2nd chart */
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(500, 60, 670, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
$image->setShadow(true, ["X" => -1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$image->drawStepChart();
$image->setShadow(false);
/* Write the chart legend */
$image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawStepChart.png");
```

View File

@ -0,0 +1,78 @@
# Drawing a stock chart
[Reference](http://wiki.pchart.net/doc.stocks.drawstockchart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Stock;
/* Create and populate the Data object */
$data = new Data();
$data->addPoints([34, 55, 15, 62, 38, 42], "Open");
$data->addPoints([42, 25, 40, 38, 49, 36], "Close");
$data->addPoints([27, 14, 12, 25, 32, 32], "Min");
$data->addPoints([45, 59, 47, 65, 64, 48], "Max");
$data->setAxisDisplay(0, AXIS_FORMAT_CURRENCY, "$");
$data->addPoints(["8h", "10h", "12h", "14h", "16h", "18h"], "Time");
$data->setAbscissa("Time");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Draw the background */
$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
/* Overlay with a gradient */
$settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
/* Draw the border */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(60, 45, "Stock price", ["FontSize" => 28, "Align" => TEXT_ALIGN_BOTTOMLEFT]);
/* Draw the 1st scale */
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(60, 60, 450, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["DrawSubTicks" => true, "CycleBackground" => true]);
/* Draw the 1st stock chart */
$mystockChart = new Stock($image, $data);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
$mystockChart->drawStockChart();
/* Reset the display mode because of the graph small size */
$data->setAxisDisplay(0, AXIS_FORMAT_DEFAULT);
/* Draw the 2nd scale */
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(500, 60, 670, 190, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 10
]);
$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
/* Draw the 2nd stock chart */
$mystockChart = new Stock($image, $data);
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
$mystockChart->drawStockChart();
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawStockChart.png");
```

View File

@ -0,0 +1,81 @@
# Drawing a surface chart
[Reference](http://wiki.pchart.net/doc.surface.drawsurface.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
use CpChart\Chart\Surface;
/* Create the Image object */
$image = new Image(400, 400);
/* Create a solid background */
$settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
"StartR" => 194,
"StartG" => 231,
"StartB" => 44,
"EndR" => 43,
"EndG" => 107,
"EndB" => 58,
"Alpha" => 50
]);
$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
"StartR" => 0,
"StartG" => 0,
"StartB" => 0,
"EndR" => 50,
"EndG" => 50,
"EndB" => 50,
"Alpha" => 100
]);
/* Add a border to the picture */
$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the picture title */
$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
$image->drawText(10, 13, "pSurface() :: 2D surface charts", ["R" => 255, "G" => 255, "B" => 255]);
/* Define the charting area */
$image->setGraphArea(20, 40, 380, 380);
$image->drawFilledRectangle(20, 40, 380, 380, [
"R" => 255,
"G" => 255,
"B" => 255,
"Surrounding" => -200,
"Alpha" => 20
]);
$image->setShadow(true, ["X" => 1, "Y" => 1]);
/* Create the surface object */
$surfaceChart = new Surface($image);
/* Set the grid size */
$surfaceChart->setGrid(20, 20);
/* Write the axis labels */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$surfaceChart->writeXLabels();
$surfaceChart->writeYLabels();
/* Add random values */
for ($i = 0; $i <= 50; $i++) {
$surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100));
}
/* Compute the missing points */
$surfaceChart->computeMissing();
/* Draw the surface chart */
$surfaceChart->drawSurface(["Border" => true, "Surrounding" => 40]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.surface.png");
```

View File

@ -0,0 +1,71 @@
# Drawing a zone chart
[Reference](http://wiki.pchart.net/doc.chart.drawzonechart.html)
```php
require '/path/to/your/vendor/autoload.php';
use CpChart\Chart\Data;
use CpChart\Chart\Image;
/* Create and populate the Data object */
$data = new Data();
for ($i = 0; $i <= 10; $i = $i + .2) {
$data->addPoints(log($i + 1) * 10, "Bounds 1");
$data->addPoints(log($i + 3) * 10 + rand(0, 2) - 1, "Probe");
$data->addPoints(log($i + 6) * 10, "Bounds 2");
$data->addPoints($i * 10, "Labels");
}
$data->setAxisName(0, "Size (cm)");
$data->setSerieDescription("Labels", "Months");
$data->setAbscissa("Labels");
$data->setAbscissaName("Time (years)");
/* Create the Image object */
$image = new Image(700, 230, $data);
/* Turn off Antialiasing */
$image->Antialias = false;
/* Add a border to the picture */
$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
/* Write the chart title */
$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
$image->drawText(150, 35, "Size by time generations", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
/* Set the default font */
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* Define the chart area */
$image->setGraphArea(40, 40, 680, 200);
/* Draw the scale */
$image->drawScale([
"LabelSkip" => 4,
"XMargin" => 10,
"YMargin" => 10,
"Floating" => true,
"GridR" => 200,
"GridG" => 200,
"GridB" => 200,
"DrawSubTicks" => true,
"CycleBackground" => true
]);
/* Turn on Antialiasing */
$image->Antialias = true;
/* Draw the line chart */
$image->drawZoneChart("Bounds 1", "Bounds 2");
$data->setSerieDrawable(["Bounds 1", "Bounds 2"], false);
/* Draw the line chart */
$image->drawStepChart();
/* Write the chart legend */
$image->drawLegend(640, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* Render the picture (choose the best way) */
$image->autoOutput("example.drawZoneChart.png");
```