Giter VIP home page Giter VIP logo

php-sparkline's Introduction

Generate sparkline SVGs in PHP

Latest Version on Packagist Tests Total Downloads

PHP-Sparkline generates GitHub style sparkline graphs. Read this guide to know how to use it.

Installation

You can install the package via composer:

composer require brendt/php-sparkline

Usage

$sparkLine = new SparkLine(1, 2, 5, 10, 2));

$total = $sparkLine->getTotal();

$svg = $sparkLine->make();

To construct a sparkline, you'll have to pass in an array of values.

Customization

You can pick any amount of colors and the sparkline will automatically generate a gradient from them:

$sparkLine = (new SparkLine($days))->withColors('#4285F4', '#31ACF2', '#2BC9F4');

You can configure the stroke width:

$sparkLine = (new SparkLine($days))->withStrokeWidth(4);

As well as the dimensions (in pixels):

$sparkLine = SparkLine::new($days)->withDimensions(width: 500, height: 100);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

php-sparkline's People

Contributors

adrianmrn avatar brendt avatar bvtterfly avatar cmgmyr avatar dependabot[bot] avatar dietercoopman avatar erikn69 avatar freekmurze avatar github-actions[bot] avatar gregkos avatar irfanm96 avatar jamessessford avatar koossaayy avatar larswiegers avatar mnaderian avatar mvdnbrk avatar nielsvanpach avatar patinthehat avatar pforret avatar riasvdv avatar thecaliskan avatar vasilejianu avatar villaflor avatar weerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

php-sparkline's Issues

The SVG render a straight line only, no matter how data is

I used the example of the docs:

$sparkLine = SparkLine::new(collect([
    new SparkLineDay(
        count: 1,
        day: new DateTimeImmutable('2022-01-01')
    ),
    new SparkLineDay(
        count: 2,
        day: new DateTimeImmutable('2022-01-02')
    ),
    new SparkLineDay(
        count: 10,
        day: new DateTimeImmutable('2022-01-03')
    ),
    new SparkLineDay(
        count: 4,
        day: new DateTimeImmutable('2022-01-04')
    ),
]));

return $sparkLink->make();

But it only renders a straight line

CleanShot 2023-06-10 at 09 17 20@2x

This is how the SVG is rendered

CleanShot 2023-06-10 at 09 23 03@2x

I am using PHP 8.2 and Laravel 10.

calculate missing entries

In version 1 was feature, where this library calculated missing dates. I miss this feature in version 2.0. It was importatnt feature.

Do you plan add some helpers to this library for recalculate SparkLineEntry based on dates ?

For example,
I have 1 count in date 1.1.2024 and one in 3.1.2.24. i need add entry for 2.1.2024 to preserve the integrity of the dates

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.