1# Sparkline 2PHP Class (using GD) to generate sparklines 3 4[![Build Status](https://app.travis-ci.com/davaxi/Sparkline.svg?branch=master)](https://app.travis-ci.com/davaxi/Sparkline) 5[![Latest Stable Version](https://poser.pugx.org/davaxi/sparkline/v/stable)](https://packagist.org/packages/davaxi/sparkline) 6[![Total Downloads](https://poser.pugx.org/davaxi/sparkline/downloads)](https://packagist.org/packages/davaxi/sparkline) 7[![Latest Unstable Version](https://poser.pugx.org/davaxi/sparkline/v/unstable)](https://packagist.org/packages/davaxi/sparkline) 8[![License](https://poser.pugx.org/davaxi/sparkline/license)](https://packagist.org/packages/davaxi/sparkline) 9[![Maintainability](https://api.codeclimate.com/v1/badges/9a5da533685204c53989/maintainability)](https://codeclimate.com/github/davaxi/Sparkline/maintainability) 10[![Test Coverage](https://api.codeclimate.com/v1/badges/9a5da533685204c53989/test_coverage)](https://codeclimate.com/github/davaxi/Sparkline/test_coverage) 11[![Issue Count](https://codeclimate.com/github/davaxi/Sparkline/badges/issue_count.svg)](https://codeclimate.com/github/davaxi/Sparkline) 12 13## Installation 14 15This page contains information about installing the Library for PHP. 16 17### Requirements 18 19- PHP version 7.0.0 or greater 20- The GD PHP extension 21- The MBString PHP extension 22 23#### Using Composer 24 25You can install the library by adding it as a dependency to your composer.json. 26 27```shell 28$ composer require davaxi/sparkline 29``` 30 31or 32 33```json 34 "require": { 35 "davaxi/sparkline": "^2.0" 36 } 37``` 38 39#### For PHP >= 5.4.0 40 41Show https://github.com/davaxi/Sparkline/tree/1.2.3 42 43## Usage 44 45Example: 46 47![Sparkline](https://raw.githubusercontent.com/davaxi/Sparkline/master/tests/data/testGenerate2-mockup.png) 48 49```php 50<?php 51 52require '/path/to/sparkline/folder/autoload.php'; 53 54$sparkline = new Davaxi\Sparkline(); 55$sparkline->setData(array(2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16)); 56$sparkline->display(); 57 58?> 59``` 60 61## Documentation 62 63```php 64$sparkline = new Davaxi\Sparkline(); 65 66// Change format (Default value 80x20) 67$sparkline->setFormat('100x40'); 68// or 69$sparkline->setWidth(100); 70$sparkline->setHeight(40); 71 72// Apply padding 73$sparkline->setPadding('10'); // > top: 10 | right: 10 | bottom: 10 | left: 10 74$sparkline->setPadding('10 20'); // > top: 10 | right: 20 | bottom: 10 | left: 20 75$sparkline->setPadding('10 20 30'); // > top: 10 | right: 20 | bottom: 30 | left: 20 76$sparkline->setPadding('10 20 30 40'); // > top: 10 | right: 20 | bottom: 30 | left: 40 77 78// Change background color (Default value #FFFFFF) 79$sparkline->setBackgroundColorHex('#0f354b'); 80// or 81$sparkline->setBackgroundColorRGB(15, 53, 75); 82// or 83$sparkline->deactivateBackgroundColor(); 84 85// Change line color (Default value #1388db) 86$sparkline->setLineColorHex('#1c628b'); 87// or 88$sparkline->setLineColorRGB(28, 98, 139); 89 90// Change line thickness (Default value 1.75 px) 91$sparkline->setLineThickness(2.2); 92 93// Change fill color (Default value #e6f2fa) 94$sparkline->setFillColorHex('#8b1c2b'); 95// or 96$sparkline->setFillColorRGB(139, 28, 43); 97// or 98$sparkline->deactivateFillColor(); 99 100$sparkline->setData(array(.....)); // Set data set 101$sparkline->getData(); // Get seted data 102$sparkline->generate(); // If ou want regenerate picture 103 104// Change base of height value (default max($data)) 105$sparkline->setBase(20); 106 107// Change origin of chart value (yAxis) (default: 0) 108$sparkline->setOriginValue(40); 109 110// Add dot on first/last/minimal/maximal value 111// Data set before used method 112$sparkline->addPoint('minimum', 3, '#efefef'); 113$sparkline->addPoint('maximum', 3, '#efefef'); 114$sparkline->addPoint('first', 3, '#efefef'); 115$sparkline->addPoint('last', 3, '#efefef'); 116 117// Or by index 118$sparkline->addPoint(1, 3, '#efefef'); 119 120// If display 121$sparkline->setEtag('your hash'); // If you want add ETag header 122$sparkline->setFilename('yourPictureName'); // For filenamen header 123$sparkline->setExpire('+1 day'); // If you want add expire header 124// or 125$sparkline->setExpire(strtotime('+1 day')); 126$sparkline->display(); // Display with correctly headers 127 128// If save 129$sparkline->save('/your/path/to/save/picture'); 130 131$sparkline->destroy(); // Destroy picture after generated / displayed / saved 132``` 133 134### Multiple sparkline series 135 136```php 137$sparkline = new Davaxi\Sparkline(); 138 139// For add series 140$sparkline->addSeries([0,1,2,3]); 141$sparkline->addSeries([2,3,5,6]); 142 143// Or 144 145$sparkline->setData( 146 [0,1,2,3], 147 [2,3,5,6] 148); 149 150// For add point on series 151$sparkline->addPoint('first', 3, '#efefef', 0); // Add point on series 0 152$sparkline->addPoint('last', 3, '#efefef', 1); // add point on series 1 153 154// For fill colors, specify on last argument series index's 155$sparkline->setFillColorHex('#8b1c2b', 0); 156$sparkline->setFillColorHex('#8bdddf', 1); 157// or 158$sparkline->setFillColorRGB(139, 28, 43, 0); 159$sparkline->setFillColorRGB(139, 28, 55, 1); 160 161// For line colors, specify on last argument series index's 162$sparkline->setLineColorHex('#1c628b', 0); 163$sparkline->setLineColorHex('#1c62df', 1); 164// or 165$sparkline->setLineColorRGB(28, 98, 139, 0); 166$sparkline->setLineColorRGB(28, 98, 55, 1);