bbsnly/chartjs-php
Composer 安装命令:
composer require bbsnly/chartjs-php
包简介
PHP wrapper for Chart.js library
README 文档
README
This package transforms how you create ChartJS elements by bringing them directly into PHP.
ChartJS-PHP eliminates the complexity of JavaScript when working with ChartJS charts. While ChartJS traditionally requires JavaScript implementation, our PHP solution delivers the same powerful charts through clean, efficient PHP code. By generating ChartJS elements directly in PHP, you write less code, maintain cleaner codebases, and deliver faster results. This is the definitive solution for PHP developers building data visualizations, dashboards, or any application requiring dynamic charts.
Note: Include the ChartJS library in your project as specified in their official documentation.
Installation
Installing ChartJS-PHP is straightforward with Composer. Run this command in your project directory:
composer require bbsnly/chartjs-php
Minimum Requirements:
- PHP version: 8.1 or higher
- ChartJS version: 2.0 or higher
Usage
Creating charts with ChartJS-PHP is simple and intuitive. Start by instantiating the Chart class, define your data, and render your chart. The library handles all the complexity for you.
Choose from our specialized chart classes for even faster development: BarChart, BubbleChart, DoughnutChart, LineChart, PieChart, PolarAreaChart, RadarChart, and ScatterChart.
Here's how to create a line chart:
use Bbsnly\ChartJs\Chart; use Bbsnly\ChartJs\Config\Data; use Bbsnly\ChartJs\Config\Dataset; use Bbsnly\ChartJs\Config\Options; $chart = new Chart; $chart->type = 'line'; $data = new Data(); $data->labels = ['Red', 'Green', 'Blue']; $dataset = new Dataset(); $dataset->data = [5, 10, 20]; $data->datasets[] = $dataset; $chart->data($data); $options = new Options(); $options->responsive = true; $chart->options($options); $chart->get(); // Returns the array of chart data $chart->toJson(); // Returns the JSON representation of the chart data $chart->toHtml('my_chart'); // Returns the HTML and JavaScript code for the chart
In the example below we will use the toHtml method to generate the HTML and JavaScript code for the chart.
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <div> <?= $chart->toHtml('my_chart'); ?> </div>
In the example below we will use the toJson method to generate the JSON representation of the chart data.
<div> <canvas id="myChart"></canvas> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script> const ctx = document.getElementById('myChart'); new Chart(ctx, <?= $chart->toJson(); ?>); </script>
Tests
Run the test suite with:
composer test
Contributing
Read our Contributing guidelines and start improving ChartJS-PHP today.
License
The ChartJS PHP is open-sourced software licensed under the MIT license.
bbsnly/chartjs-php 适用场景与选型建议
bbsnly/chartjs-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 107.57k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2017 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「chartjs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bbsnly/chartjs-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bbsnly/chartjs-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bbsnly/chartjs-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 chartjs
A chartjs widget for laravel nova-dashboard.
Alfabank REST API integration
Chart js back-end service for laravel
Use Chartjs in laravel-admin
build awesome charts directly from your ORM Entities
统计信息
- 总下载量: 107.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-17