All Projects → halfpastfouram → phpchartjs

halfpastfouram / phpchartjs

Licence: AGPL-3.0 license
A PHP library that makes it easy to generate data for ChartJS.

Programming Languages

PHP
23972 projects - #3 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to phpchartjs

Composer Lock Diff
See what has changed after a composer update
Stars: ✭ 154 (+541.67%)
Mutual labels:  composer, lock
composer-diff
Compares composer.lock changes and generates Markdown report so you can use it in PR description.
Stars: ✭ 51 (+112.5%)
Mutual labels:  composer, lock
chartjs-plugin-datasource-prometheus
Chart.js plugin for Prometheus data loading
Stars: ✭ 77 (+220.83%)
Mutual labels:  chartjs
bigflow
A Python framework for data processing on GCP.
Stars: ✭ 96 (+300%)
Mutual labels:  composer
charts
Laravel Enso Charts is a VueJS, wrapper for Chart.js, with a backend data builder, so you can add beautiful charts to your application
Stars: ✭ 15 (-37.5%)
Mutual labels:  chartjs
Voice4Rural
A complete one stop solution for all the problems of Rural area people. 👩🏻‍🌾
Stars: ✭ 12 (-50%)
Mutual labels:  chartjs
gdoo
Gdoo是基于PHP Laravel框架的开源OA/协同办公平台,包含销售管理、日程安排,进销存、数据分析,强大的自定义能力。改进销售管理模式,提升企业执行效率
Stars: ✭ 111 (+362.5%)
Mutual labels:  composer
chartjs-plugin-piechart-outlabels
Highly customizable Chart.js plugin that displays labels outside the pie/doughnut chart.
Stars: ✭ 46 (+91.67%)
Mutual labels:  chartjs
Chart.js-Rounded-Bar-Charts
Rounded Rectangles in Bar Charts
Stars: ✭ 48 (+100%)
Mutual labels:  chartjs
dashblocks-template
Dashblocks Vue Material Admin Template
Stars: ✭ 143 (+495.83%)
Mutual labels:  chartjs
igni-core
UNSUPPORTED: An easy to use & featherlight CMS that shortcuts the bootstrapping of backend PHP + MySQL based projects. Developed in Laravel, it uses the latest PHP coding standards and library versions.
Stars: ✭ 13 (-45.83%)
Mutual labels:  composer
ci
Run npm ci using the appropriate Node package manager (npm, yarn, pnpm)
Stars: ✭ 39 (+62.5%)
Mutual labels:  lock
Ticket-Travel-Management-System
It's a e_Ticketing platform, it has whole ticket reservation system as like ixigo.com. Now three types of traveling such as Flight, Bus and Train reservation system. It's a responsive and dynamic PHP website.
Stars: ✭ 39 (+62.5%)
Mutual labels:  chartjs
wordpress-bundle
Use Wordpress and Symfony together using a Symfony bundle
Stars: ✭ 30 (+25%)
Mutual labels:  composer
nova-chartjs
A Chart JS component for Laravel Nova
Stars: ✭ 47 (+95.83%)
Mutual labels:  chartjs
competiwatch-desktop
Desktop app built in Electron for tracking your competitive match history in Overwatch.
Stars: ✭ 94 (+291.67%)
Mutual labels:  chartjs
activejob-uniqueness
Unique jobs for ActiveJob. Ensure the uniqueness of jobs in the queue.
Stars: ✭ 194 (+708.33%)
Mutual labels:  lock
github-user-languages
Browser extension that adds little language pie charts to a user's profile page on GitHub.
Stars: ✭ 41 (+70.83%)
Mutual labels:  chartjs
chart
📊📉 Add beautiful and reusable charts with one line of ruby for Rails 5.x
Stars: ✭ 42 (+75%)
Mutual labels:  chartjs
chartjs-chart-timeline
Google-like timeline chart for Chart.js.
Stars: ✭ 44 (+83.33%)
Mutual labels:  chartjs

Stable

Latest Stable Version Total Downloads License composer.lock Build Status Code Climate Test Coverage Quality

Development

Latest Unstable Version Build Status

PHPChartJS

PHP OOP library for ChartJS

PHPChartJS acts as an interface between the ChartJS library and the server side code. Set up a chart in no time and have every aspect of the graph managable from your PHP code. This interface is set up to provide code completion in every scenario so you never have to guess or lookup what options are available for the chosen chart. The library is entirely object oriented.

This library is still in active development and aims to implement all options ChartJS has to offer. Check the Configuration milestone to view the progress of implementing all existing options.

Example use

<?php
use Halfpastfour\PHPChartJS\Chart\Bar;

$bar = new Bar();
$bar->setId("myBar");

// Set labels
$bar->labels()->exchangeArray(["M", "T", "W", "T", "F", "S", "S"]);

// Add apples
$apples = $bar->createDataSet();
$apples->setLabel("apples")
  ->setBackgroundColor("rgba( 0, 150, 0, .5 )")
  ->data()->exchangeArray([12, 19, 3, 17, 28, 24, 7]);
$bar->addDataSet($apples);

// Add oranges as well
$oranges = $bar->createDataSet();
$oranges->setLabel("oranges")
  ->setBackgroundColor("rgba( 255, 153, 0, .5 )")
  ->data()->exchangeArray([ 30, 29, 5, 5, 20, 3 ]);
  
// Add some extra data
$oranges->data()->append(10);

$bar->addDataSet($oranges);

// Render the chart
echo $bar->render();

The result generated by rendering the chart will look something like this:

<canvas id="myBar"></canvas>
<script>
window.onload=(function(oldLoad){return function(){
if( oldLoad ) oldLoad();
var ctx = document.getElementById( "myBar" ).getContext( "2d" );
var chart = new Chart( ctx, {"type":"bar","data":{"labels":["M","T","W","T","F","S","S"],"datasets":[{"data":[12,19,3,17,28,24,7],"label":"apples","backgroundColor":"rgba( 0, 150, 0, .5 )"},{"data":[30,29,5,5,20,3,10],"label":"oranges","backgroundColor":"rgba( 255, 153, 0, .5 )"}]}} );
}})(window.onload);
</script>

Callbacks

You can provide javascript callbacks with ease:

$myCallback = "function(item){ console.log(item); }";
$bar->options()->getTooltips()->callbacks()->setAfterBody($myCallback);

Rendering

Rendering the chart creates some HTML and some JavaScript. The JavaScript contains a JSON object providing the necessary configuration for ChartJS. Every part of the configuration can be cast to an array or a JSON object.

Render isolated part of the configuration:

$json = $myChart->options()->getScales()->jsonSerialize();

Or return an array containing the set configuration:

$options = $myChart->options()->getScales()->getArrayCopy();

Pretty mode

If you're not a fan of the long lines of code that are being generated you can force the rendering to be done in pretty mode, see the following example.

// Render in pretty mode
$bar->render(true);

Want to see more? Fork this project and take a look at the examples in the test folder to explore the different options.

Configuration options

Every option that is supported by ChartJS will be made available in this library.

Layers

ChartJS requires you to build a JSON object containing the configuration options you want to set for the current chart. These options are spread over multiple layers inside the configuration object. Accessing these layers with PHPChartJS is super easy.

Let's say we wanted to access the chart's getAnimation subtree within the options subtree:

$getAnimation = $myChart->options()->getAnimation();

You can now adjust any of ChartJS's getAnimation settings by using the getters and setters provided in that particular class.

Collections

If ChartJS requires an array with certain items as subsets in a configuration option that array will be represented by a collection in PHPChartJS. The collection can always by accessed directly to add, remove and replace values.

In some cases a specific object with a predetermined list of options is required in a collection. In these cases methods will be provided to create a new instance of said object and adding it to the collection.

Datasets are stored in a collection:

// Create new dataset
$dataset = $myChart->createDataSet();
... (add data to the dataset)
$myChart->addDataSet($dataset);

But the actual data in a dataset is also stored inside a collection:

// Create new dataset
$dataset = $myChart->createDataSet();

// Add some data 
$dataset->data()->append(1)->append(2);

// Prepend some data
$dataset->data()->prepend(0);

// Replace data at certain position
$dataset->data()->offsetSet(1, 3);

// Retrieve data from certain position
$value = $dataset->data()->offsetGet(1); // 3

// Add a lot of data at once whilst returning the old values
$oldData = $dataset->data()->exchangeArray([1, 2, 3]); // array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }

$myChart->addDataSet($dataset);

For more information about the collections visit the halfpastfouram/collection project.

Installation

Using composer

$ composer require halfpastfouram/phpchartjs

Development

This project uses composer, which should be installed on your system. Most Linux systems have composer available in their PHP packages. Alternatively you can download composer from getcomposer.org.

If you use the PhpStorm IDE then you can simply init composer through the IDE. However, full use requires the commandline. See PhpStorm help, search for composer.

To start development, do composer install from the project directory.

Remark Do not use composer update unless you changed the dependency requirements in composer.json. The difference is that composer install will use composer.lock read-only, while composer update will update your composer.lock file regardless of any change. As the composer.lock file is committed to the repo, other developers might conclude dependencies have changed, while they have not.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].