{"id":33970657,"url":"https://github.com/halfpastfouram/phpchartjs","last_synced_at":"2026-04-05T01:31:31.071Z","repository":{"id":62514150,"uuid":"74228285","full_name":"halfpastfouram/phpchartjs","owner":"halfpastfouram","description":"A PHP library that makes it easy to generate data for ChartJS.","archived":false,"fork":false,"pushed_at":"2023-03-24T17:49:02.000Z","size":384,"stargazers_count":25,"open_issues_count":9,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-12-14T13:17:16.731Z","etag":null,"topics":["chartjs","composer","javascript","lock","php"],"latest_commit_sha":null,"homepage":"https://halfpastfouram.github.io/phpchartjs/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/halfpastfouram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-19T18:50:19.000Z","updated_at":"2024-02-20T10:35:05.000Z","dependencies_parsed_at":"2022-11-02T12:16:03.534Z","dependency_job_id":null,"html_url":"https://github.com/halfpastfouram/phpchartjs","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/halfpastfouram/phpchartjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halfpastfouram%2Fphpchartjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halfpastfouram%2Fphpchartjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halfpastfouram%2Fphpchartjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halfpastfouram%2Fphpchartjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halfpastfouram","download_url":"https://codeload.github.com/halfpastfouram/phpchartjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halfpastfouram%2Fphpchartjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31421869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T00:25:07.052Z","status":"ssl_error","status_checked_at":"2026-04-05T00:25:05.923Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chartjs","composer","javascript","lock","php"],"created_at":"2025-12-13T00:35:27.834Z","updated_at":"2026-04-05T01:31:31.061Z","avatar_url":"https://github.com/halfpastfouram.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Stable\n[![Latest Stable Version](https://poser.pugx.org/halfpastfouram/phpchartjs/v/stable)](https://packagist.org/packages/halfpastfouram/phpchartjs)\n[![Total Downloads](https://poser.pugx.org/halfpastfouram/phpchartjs/downloads)](https://packagist.org/packages/halfpastfouram/phpchartjs)\n[![License](https://poser.pugx.org/halfpastfouram/phpchartjs/license)](https://packagist.org/packages/halfpastfouram/phpchartjs)\n[![composer.lock](https://poser.pugx.org/halfpastfouram/phpchartjs/composerlock)](https://packagist.org/packages/halfpastfouram/phpchartjs)\n[![Build Status](https://travis-ci.org/halfpastfouram/PHPChartJS.svg?branch=master)](https://travis-ci.org/halfpastfouram/PHPChartJS)\n[![Code Climate](https://codeclimate.com/github/halfpastfouram/PHPChartJS/badges/gpa.svg)](https://codeclimate.com/github/halfpastfouram/PHPChartJS)\n[![Test Coverage](https://codeclimate.com/github/halfpastfouram/PHPChartJS/badges/coverage.svg)](https://codeclimate.com/github/halfpastfouram/PHPChartJS/coverage)\n[![Quality](https://scrutinizer-ci.com/g/halfpastfouram/PHPChartJS/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/halfpastfouram/PHPChartJS/)\n\n### Development\n[![Latest Unstable Version](https://poser.pugx.org/halfpastfouram/phpchartjs/v/unstable)](https://packagist.org/packages/halfpastfouram/phpchartjs)\n[![Build Status](https://travis-ci.org/halfpastfouram/PHPChartJS.svg?branch=dev)](https://travis-ci.org/halfpastfouram/PHPChartJS)\n\n# PHPChartJS\nPHP OOP library for [ChartJS](http://www.chartjs.org/)\n\nPHPChartJS 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.\n\nThis library is still in active development and aims to implement all options ChartJS has to offer. Check the [Configuration milestone](https://github.com/halfpastfouram/PHPChartJS/milestone/1) to view the progress of implementing all existing options.\n\n## Example use\n````php\n\u003c?php\nuse Halfpastfour\\PHPChartJS\\Chart\\Bar;\n\n$bar = new Bar();\n$bar-\u003esetId(\"myBar\");\n\n// Set labels\n$bar-\u003elabels()-\u003eexchangeArray([\"M\", \"T\", \"W\", \"T\", \"F\", \"S\", \"S\"]);\n\n// Add apples\n$apples = $bar-\u003ecreateDataSet();\n$apples-\u003esetLabel(\"apples\")\n  -\u003esetBackgroundColor(\"rgba( 0, 150, 0, .5 )\")\n  -\u003edata()-\u003eexchangeArray([12, 19, 3, 17, 28, 24, 7]);\n$bar-\u003eaddDataSet($apples);\n\n// Add oranges as well\n$oranges = $bar-\u003ecreateDataSet();\n$oranges-\u003esetLabel(\"oranges\")\n  -\u003esetBackgroundColor(\"rgba( 255, 153, 0, .5 )\")\n  -\u003edata()-\u003eexchangeArray([ 30, 29, 5, 5, 20, 3 ]);\n  \n// Add some extra data\n$oranges-\u003edata()-\u003eappend(10);\n\n$bar-\u003eaddDataSet($oranges);\n\n// Render the chart\necho $bar-\u003erender();\n````\nThe result generated by rendering the chart will look something like this:\n\n````html\n\u003ccanvas id=\"myBar\"\u003e\u003c/canvas\u003e\n\u003cscript\u003e\nwindow.onload=(function(oldLoad){return function(){\nif( oldLoad ) oldLoad();\nvar ctx = document.getElementById( \"myBar\" ).getContext( \"2d\" );\nvar 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 )\"}]}} );\n}})(window.onload);\n\u003c/script\u003e\n````\n\n### Callbacks\nYou can provide javascript callbacks with ease:\n\n````php\n$myCallback = \"function(item){ console.log(item); }\";\n$bar-\u003eoptions()-\u003egetTooltips()-\u003ecallbacks()-\u003esetAfterBody($myCallback);\n````\n\n### Rendering\n\nRendering the chart creates some HTML and some JavaScript. The JavaScript contains a JSON object providing the necessary\nconfiguration for ChartJS. Every part of the configuration can be cast to an array or a JSON object.\n\nRender isolated part of the configuration:\n\n````php\n$json = $myChart-\u003eoptions()-\u003egetScales()-\u003ejsonSerialize();\n````\n\nOr return an array containing the set configuration:\n\n````php\n$options = $myChart-\u003eoptions()-\u003egetScales()-\u003egetArrayCopy();\n````\n\n\n### Pretty mode\nIf 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.\n\n````php\n// Render in pretty mode\n$bar-\u003erender(true);\n````\n\nWant to see more? Fork this project and take a look at the examples in the test folder to explore the different options.\n\n## Configuration options\nEvery option that is supported by ChartJS will be made available in this library.\n\n### Layers\nChartJS requires you to build a JSON object containing the configuration options you want to set for the current chart.\nThese options are spread over multiple layers inside the configuration object. Accessing these layers with PHPChartJS is\n super easy.\n\nLet's say we wanted to access the chart's getAnimation subtree within the options subtree:\n````php\n$getAnimation = $myChart-\u003eoptions()-\u003egetAnimation();\n````\nYou can now adjust any of ChartJS's getAnimation settings by using the getters and setters provided in that particular class.\n\n## Collections\nIf ChartJS requires an array with certain items as subsets in a configuration option that array will be represented by a\ncollection in PHPChartJS. The collection can always by accessed directly to add, remove and replace values.\n\nIn some cases a specific object with a predetermined list of options is required in a collection. In these cases methods\nwill be provided to create a new instance of said object and adding it to the collection.\n\nDatasets are stored in a collection:\n\n````php\n// Create new dataset\n$dataset = $myChart-\u003ecreateDataSet();\n... (add data to the dataset)\n$myChart-\u003eaddDataSet($dataset);\n````\n\nBut the actual data in a dataset is also stored inside a collection:\n\n````php\n// Create new dataset\n$dataset = $myChart-\u003ecreateDataSet();\n\n// Add some data \n$dataset-\u003edata()-\u003eappend(1)-\u003eappend(2);\n\n// Prepend some data\n$dataset-\u003edata()-\u003eprepend(0);\n\n// Replace data at certain position\n$dataset-\u003edata()-\u003eoffsetSet(1, 3);\n\n// Retrieve data from certain position\n$value = $dataset-\u003edata()-\u003eoffsetGet(1); // 3\n\n// Add a lot of data at once whilst returning the old values\n$oldData = $dataset-\u003edata()-\u003eexchangeArray([1, 2, 3]); // array(3) { [0]=\u003e int(1) [1]=\u003e int(2) [2]=\u003e int(3) }\n\n$myChart-\u003eaddDataSet($dataset);\n````\nFor more information about the collections visit the [halfpastfouram/collection](https://github.com/halfpastfouram/collection) project.\n\n## Installation\n\n### Using composer\n    $ composer require halfpastfouram/phpchartjs\n\n### Development\nThis project uses composer, which should be installed on your system. Most\nLinux systems have composer available in their PHP packages.\nAlternatively you can download composer from [getcomposer.org](http://getcomposer.org).\n\nIf you use the PhpStorm IDE then you can simply init composer through the IDE. However,\nfull use requires the commandline. See PhpStorm help, search for composer.\n\nTo start development, do `composer install` from the project directory. \n\n**Remark** Do not use `composer update` unless you changed the dependency requirements in composer.json.\nThe difference is that `composer install` will use composer.lock read-only, \nwhile `composer update` will update your composer.lock file regardless of any change.\nAs the composer.lock file is committed to the repo, other developers might conclude \ndependencies have changed, while they have not.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalfpastfouram%2Fphpchartjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalfpastfouram%2Fphpchartjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalfpastfouram%2Fphpchartjs/lists"}