ejdamm/chart.js-php
Composer 安装命令:
composer require ejdamm/chart.js-php
包简介
PHP Wrapper for Chart.js.
README 文档
README
A PHP wrapper for chartjs/Chart.js This project is an expansion of HugoHeneault's repository
How to use
Include js/Chart.min.js and js/driver.js before the end of your body (change src according to your project). If you want to use CDN instead see [here](. For CDN see here https://cdnjs.com/libraries/Chart.js)
<html> <body> <!-- Your awesome project comes here --> <!-- And here are Chart.js --> <script src="js/Chart.min.js"></script> <script src="js/driver.js"></script> </body> </html>
Install ChartJS-PHP via composer
{
"repositories": [
{
"type": "git",
"url": "https://github.com/Ejdamm/Chart.js-PHP"
}],
"require": {
"ejdamm/chart.js-php": "dev-master"
}
}
Then, create your charts using PHP.
$data = [ 'labels' => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'datasets' => [[ 'data' =>[8, 7, 8, 9, 6], 'backgroundColor' => '#f2b21a', 'borderColor' => '#e5801d', 'label' => 'Legend' ]] ]; $options = []; $attributes = ['id' => 'example', 'width' => 500, 'height' => 500]; $Line = new ChartJs\ChartJS('line', $data, $options, $attributes); // Echo your line echo $Line; ?>
Finally, load these charts with a small piece of javascript when your document is ready
// Pure JS document.ready (function() { loadChartJsPhp(); })();
Full example
<?php require 'vendor/autoload.php'; use ChartJs\ChartJS; $data = [ 'labels' => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'datasets' => [[ 'data' =>[8, 7, 8, 9, 6], 'backgroundColor' => '#f2b21a', 'borderColor' => '#e5801d', 'label' => 'Legend' ]] ]; $options = ['responsive' => false]; $attributes = ['id' => 'example', 'width' => 500, 'height' => 500]; $Line = new ChartJS('line', $data, $options, $attributes); ?><!DOCTYPE html> <html> <head> <title>Chart.js-PHP</title> </head> <body> <?php echo $Line; ?> <script src="vendor/Ejdamm/Chart.js-PHP/js/Chart.min.js"></script> <script src="vendor/Ejdamm/Chart.js-PHP/js/driver.js"></script> <script> (function() { loadChartJsPhp(); })(); </script> </body> </html>
Documentation
Full documentation is available at Chart.js website. There you can find what type of charts and associated properties are available.
Time axis
If you are going to use time axis you need either to include Moment.js or Chart.bundle.js instead of Chart.js to your project. Chart.bundle.js consists of both Chart.js and Moment.js (which is needed for time axis).
Contributing
Do not hesitate to edit or improve my code with bugfix and new functionalities!
ejdamm/chart.js-php 适用场景与选型建议
ejdamm/chart.js-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.35k 次下载、GitHub Stars 达 34, 最近一次更新时间为 2019 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ejdamm/chart.js-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ejdamm/chart.js-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-19