### Create a scatter threshold area chart in PHP Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/scatter_threshold_area.md This example demonstrates setting up data series from functions, configuring axes, and rendering a scatter chart with a highlighted threshold area. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Chart\Scatter; use CpChart\Data; use CpChart\Image; /* 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"); ``` -------------------------------- ### Create a filled spline chart in PHP Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/filled_spline.md Demonstrates the full workflow for initializing data, configuring the image canvas, drawing the spline chart, and rendering the output. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Data; use CpChart\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"); ``` -------------------------------- ### Install c-pchart via Composer Source: https://github.com/szymach/c-pchart/blob/3.1/README.md Add the dependency to your composer.json file or run the command in your project root. ```json "require": { "szymach/c-pchart": "^3.1" }, ``` ```sh $ composer require szymach/c-pchart ``` -------------------------------- ### Store and retrieve chart data with Cache Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/cache.md Demonstrates initializing the cache, generating a hash for chart data, and performing various output operations from the cache. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Cache; use CpChart\Data; use CpChart\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) ``` -------------------------------- ### Draw spline charts with pChart Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/spline.md Demonstrates how to initialize data, configure spline settings like control points and ticks, and render the output image. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Data; use CpChart\Image; // Create and populate data $data = new Data(); $data->addPoints([], "Serie1"); // Create the image and set the data $image = new Image(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"); ``` -------------------------------- ### Render a stock chart with PHP Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/stock.md Demonstrates the full workflow of creating a Data object, configuring the Image canvas, and rendering two distinct stock chart areas. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Chart\Stock; use CpChart\Data; use CpChart\Image; /* 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"); ``` -------------------------------- ### Create a 2D ring chart with pChart Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/2d_ring.md Initializes data, configures image aesthetics, and renders a 2D ring chart using the Pie class. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Chart\Pie; use CpChart\Data; use CpChart\Image; /* 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"); ``` -------------------------------- ### Draw a filled step chart with PHP Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/filled_step.md Demonstrates the full workflow of creating a Data object, configuring an Image object, and rendering a filled step chart with custom styling and legends. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Data; use CpChart\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"); ``` -------------------------------- ### Draw a bar chart with PHP Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/bar.md Initializes a Data object, configures chart aesthetics, and renders a bar chart to an image file. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Data; use CpChart\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"); ``` -------------------------------- ### Draw a 3D ring chart with pChart Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/3d_ring.md Initializes a data set, configures the image canvas with gradients and borders, and renders a 3D ring chart using the Pie class. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Chart\Pie; use CpChart\Data; use CpChart\Image; /* 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"); ``` -------------------------------- ### Create a 2D surface chart with CpChart Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/surface.md Initializes an image, sets up the drawing area, adds random data points, and renders a surface chart to a file. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Chart\Surface; use CpChart\Data; use CpChart\Image; /* 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"); ``` -------------------------------- ### Draw a split path chart in PHP Source: https://github.com/szymach/c-pchart/blob/3.1/resources/doc/split_path.md Initializes the image canvas, populates data points, and renders two split path charts with different configurations. ```php require '/path/to/your/vendor/autoload.php'; use CpChart\Data; use CpChart\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"); ```