\ChartMancer
The ChartMancer class automates the generation of graphs based on data provided in an array.
It utilizes the GD library to create visually appealing charts, allowing developers to easily
visualize and display data trends. With ChartMancer, you can customize various aspects of the
graph, such as colors, labels, and other chart properties, providing a versatile tool
for data representation in PHP applications.
- Author: Rostyslav Haitkulov <info@ubilling.net.ua>
- License: MIT
Synopsis
class ChartMancer
{
- // members
- protected string $chartTitle = '';
- protected string $palette = 'O-M-G';
- protected integer $imageWidth = 1540;
- protected integer $imageHeight = 400;
- protected integer $gridTop = 40;
- protected integer $gridLeft = 50;
- protected integer $lineWidth = 1;
- protected integer $barWidth = 5;
- protected integer $labelMargin = 8;
- protected array $chartLegend = ;
- protected array $baseColor = ;
- protected array $backGroundColor = ;
- protected array $gridColor = ;
- protected array $axisColor = ;
- protected array $textColor = ;
- protected array $overrideColors = ;
- protected bool $backgroundTransparent = false;
- protected string $font = 'skins/OpenSans-Regular.ttf';
- protected integer $fontSize = 10;
- protected integer $xLabelLen = 5;
- protected integer $xAxisLabelCount = 20;
- protected string $cutSuffix = '...';
- protected bool $displayPeakValue = false;
- protected string $yAxisName = '';
- protected bool $debug = false;
- protected bool $barAutoWidth = true;
- protected float $yMaxValueRatio = 0.1;
- protected bool $xLabelRender = true;
- protected bool $yLabelRender = true;
- protected bool $drawFirstColumnAlways = true;
- // methods
- public void __construct()
- protected array getColorFromText()
- protected bool checkColor()
- public void setBarAutoWidth()
- public void setPalette()
- public void setImageWidth()
- public void setImageHeight()
- public void setBarWidth()
- public void setBaseColor()
- public void setBackGroundColor()
- public void setGridColor()
- public void setAxisColor()
- public void setXLabelLen()
- public void setXLabelsCount()
- public void setCutSuffix()
- public void setBackgroundTransparent()
- public void setFont()
- public void setFontSize()
- public void setDebug()
- public ChartMancer setTextColor()
- public void setChartTitle()
- public void setDisplayPeakValue()
- public void setChartLegend()
- public void setChartYaxisName()
- public void setOverrideColors()
- public void setYMaxValueRatio()
- public void setDrawFirstColumn()
- public void setXLabelRender()
- public void setYLabelRender()
- public bool|string renderChart()
- public void getChartBase()
Members
protected
- $axisColor
—
array
Contains default axis color RGB decimal values. - $backGroundColor
—
array
Contains default background color RGB decimal values. White by default. - $backgroundTransparent
—
bool
Transparent background transparency flag - $barAutoWidth
—
bool
Bar automatic width modifier depend on data set size - $barWidth
—
int
Bar default width in px - $baseColor
—
array
Contains default base color RGB decimal values - $chartLegend
—
array
Contains optional chart legend - $chartTitle
—
string
Custom chart chart title - $cutSuffix
—
string
Contains cutted string suffix - $debug
—
bool
Rendering debug flag - $displayPeakValue
—
bool
Render maximum dataset value on chart? - $drawFirstColumnAlways
—
bool
Prevents first (totals) data column from marking as already drawn - $font
—
string
TTF font path - $fontSize
—
int
Font size in pt. - $gridColor
—
array
Contains default grid color RGB decimal values. - $gridLeft
—
int
Grid dimensions and placement within chart, left side, px - $gridTop
—
int
Grid dimensions and placement within chart, top side, px - $imageHeight
—
int
Image dimensions, height in px - $imageWidth
—
int
Image dimensions, width in px - $labelMargin
—
int
Margin between label and axis in px - $lineWidth
—
int
Grid line width in px - $overrideColors
—
array
Dynamic palette overrides - $palette
—
string
Custom colors palette modifier - $textColor
—
array
Contains default text color RGB decimal values. - $xAxisLabelCount
—
int
Contains X-axis labels count - $xLabelLen
—
int
Maximum length of x-Axis label text - $xLabelRender
—
bool
X-Axis text labels rendering flag - $yAxisName
—
string
Contains custom Y-axis label - $yLabelRender
—
bool
Y-Axis text labels rendering flag - $yMaxValueRatio
—
float
Contains y-max ratio offset from max dataset value to upper grid limit
Methods
protected
- checkColor() — Checks is array contains valid RGB values or not?
- getColorFromText() — Returns a decimal RGB color based on text string as array(r/g/b)
public
- __construct()
- getChartBase() — Returns current chart as base64 encoded text
- renderChart() — Renders chart as PNG image into browser or into specified file
- setAxisColor() — Set default axis color RGB decimal values.
- setBackGroundColor() — Set default background color RGB decimal values. White by default.
- setBackgroundTransparent() — Set transparent background transparency flag
- setBarAutoWidth() — Set bar automatic width modifier depend on data set size
- setBarWidth() — Set bar default width in px
- setBaseColor() — Set default base color RGB decimal values
- setChartLegend() — Sets optional chart legend
- setChartTitle() — Sets chart chartTitle
- setChartYaxisName() — Sets custom Y-axis name
- setCutSuffix() — Sets cutted labels suffix value
- setDebug() — Sets rendering debug flag
- setDisplayPeakValue() — Sets maximum dataset value rendering on chart flag
- setDrawFirstColumn() — Sets the state of drawing the explict first (totals) column flag.
- setFont() — Set TTF font path
- setFontSize() — Set font size in pt.
- setGridColor() — Set default grid color RGB decimal values.
- setImageHeight() — Set image dimensions, height in px
- setImageWidth() — Set image dimensions, width in px
- setOverrideColors() — Sets custom colors overrides as array of RGB decimal values.
- setPalette() — Set custom colors palette modifier
- setTextColor() — Set default text color RGB decimal values.
- setXLabelLen() — Sets X-axis labels length in bytes
- setXLabelRender() — Sets X-Axis text labels rendering flag
- setXLabelsCount() — Sets X-axis labels count
- setYLabelRender() — Sets Y-Axis text labels rendering flag
- setYMaxValueRatio() — Sets the maximum value ratio for the y-axis.