Sparkline

PHP Class (using GD) to generate sparklines

  • 所有者: davaxi/Sparkline
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Sparkline

PHP Class (using GD) to generate sparklines

Build Status
Latest Stable Version
Total Downloads
Latest Unstable Version
License
Maintainability
Test Coverage
Issue Count

Installation

This page contains information about installing the Library for PHP.

Requirements

  • PHP version 5.4.0 or greater
  • The GD PHP extension

Obtaining the client library

There are two options for obtaining the files for the client library.

Using Composer

You can install the library by adding it as a dependency to your composer.json.

  "require": {
    "davaxi/sparkline": "^1.2"
  }

Cloning from GitHub

The library is available on GitHub. You can clone it into a local repository with the git clone command.

git clone https://github.com/davaxi/Sparkline.git

What to do with the files

After obtaining the files, ensure they are available to your code. If you're using Composer, this is handled for you automatically. If not, you will need to add the autoload.php file inside the client library.

require '/path/to/sparkline/folder/autoload.php';

Usage

Example:

Sparkline

<?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

$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
$sparkline->deactivateFillColor();

$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

$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);

主要指标

概览
名称与所有者davaxi/Sparkline
主编程语言PHP
编程语言PHP (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2015-11-15 09:27:24
推送于2023-02-20 15:31:33
最后一次提交2022-06-17 15:00:13
发布数18
最新版本名称2.2.0 (发布于 )
第一版名称1.0.0 (发布于 )
用户参与
星数66
关注者数6
派生数17
提交数88
已启用问题?
问题数11
打开的问题数0
拉请求数13
打开的拉请求数1
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?