1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
# Sparkline
PHP Class (using GD) to generate sparklines
[](https://app.travis-ci.com/davaxi/Sparkline)
[](https://packagist.org/packages/davaxi/sparkline)
[](https://packagist.org/packages/davaxi/sparkline)
[](https://packagist.org/packages/davaxi/sparkline)
[](https://packagist.org/packages/davaxi/sparkline)
[](https://codeclimate.com/github/davaxi/Sparkline/maintainability)
[](https://codeclimate.com/github/davaxi/Sparkline/test_coverage)
[](https://codeclimate.com/github/davaxi/Sparkline)
## Installation
This page contains information about installing the Library for PHP.
### Requirements
- PHP version 7.0.0 or greater
- The GD PHP extension
- The MBString PHP extension
#### Using Composer
You can install the library by adding it as a dependency to your composer.json.
```shell
$ composer require davaxi/sparkline
```
or
```json
"require": {
"davaxi/sparkline": "^2.2"
}
```
#### For PHP >= 5.4.0
Show https://github.com/davaxi/Sparkline/tree/1.2.3
## Usage
Example:

```php
<?php
require '/path/to/sparkline/folder/autoload.php';
$sparkline = new Davaxi\Sparkline();
$sparkline->setData(array(2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16));
$sparkline->display();
?>
```
## Documentation
```php
$sparkline = new Davaxi\Sparkline();
// Change format (Default value 80x20)
$sparkline->setFormat('100x40');
// or
$sparkline->setWidth(100);
$sparkline->setHeight(40);
// Apply padding
$sparkline->setPadding('10'); // > top: 10 | right: 10 | bottom: 10 | left: 10
$sparkline->setPadding('10 20'); // > top: 10 | right: 20 | bottom: 10 | left: 20
$sparkline->setPadding('10 20 30'); // > top: 10 | right: 20 | bottom: 30 | left: 20
$sparkline->setPadding('10 20 30 40'); // > top: 10 | right: 20 | bottom: 30 | left: 40
// Change background color (Default value #FFFFFF)
$sparkline->setBackgroundColorHex('#0f354b');
// or
$sparkline->setBackgroundColorRGB(15, 53, 75);
// or
$sparkline->deactivateBackgroundColor();
// Change line color (Default value #1388db)
$sparkline->setLineColorHex('#1c628b');
// or
$sparkline->setLineColorRGB(28, 98, 139);
// Change line thickness (Default value 1.75 px)
$sparkline->setLineThickness(2.2);
// Change fill color (Default value #e6f2fa)
$sparkline->setFillColorHex('#8b1c2b');
// or
$sparkline->setFillColorRGB(139, 28, 43);
// or for specific series
$sparkline->deactivateFillColor();
// or for all series
$sparkline->deactivateAllFillColor();
$sparkline->setData(array(.....)); // Set data set
$sparkline->getData(); // Get seted data
$sparkline->generate(); // If ou want regenerate picture
// Change base of height value (default max($data))
$sparkline->setBase(20);
// Change origin of chart value (yAxis) (default: 0)
$sparkline->setOriginValue(40);
// Add dot on first/last/minimal/maximal value
// Data set before used method
$sparkline->addPoint('minimum', 3, '#efefef');
$sparkline->addPoint('maximum', 3, '#efefef');
$sparkline->addPoint('first', 3, '#efefef');
$sparkline->addPoint('last', 3, '#efefef');
// Or by index
$sparkline->addPoint(1, 3, '#efefef');
// If display
$sparkline->setEtag('your hash'); // If you want add ETag header
$sparkline->setFilename('yourPictureName'); // For filenamen header
$sparkline->setExpire('+1 day'); // If you want add expire header
// or
$sparkline->setExpire(strtotime('+1 day'));
$sparkline->display(); // Display with correctly headers
// If save
$sparkline->save('/your/path/to/save/picture');
$sparkline->destroy(); // Destroy picture after generated / displayed / saved
```
### Multiple sparkline series
```php
<?php
$sparkline = new Davaxi\Sparkline();
// For add series
$sparkline->addSeries([0,1,2,3]);
$sparkline->addSeries([2,3,5,6]);
// Or
$sparkline->setData(
[0,1,2,3],
[2,3,5,6]
);
// For add point on series
$sparkline->addPoint('first', 3, '#efefef', 0); // Add point on series 0
$sparkline->addPoint('last', 3, '#efefef', 1); // add point on series 1
// For fill colors, specify on last argument series index's
$sparkline->setFillColorHex('#8b1c2b', 0);
$sparkline->setFillColorHex('#8bdddf', 1);
// or
$sparkline->setFillColorRGB(139, 28, 43, 0);
$sparkline->setFillColorRGB(139, 28, 55, 1);
// For line colors, specify on last argument series index's
$sparkline->setLineColorHex('#1c628b', 0);
$sparkline->setLineColorHex('#1c62df', 1);
// or
$sparkline->setLineColorRGB(28, 98, 139, 0);
$sparkline->setLineColorRGB(28, 98, 55, 1);
```
|