定制 danielpetrica/svg-charts 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danielpetrica/svg-charts

Composer 安装命令:

composer require danielpetrica/svg-charts

包简介

A PHP library to create svg charts for your data. No external js, no external dependancies just plain svg images

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A PHP library to create SVG charts for your data. No external JavaScript, no external dependencies - just plain SVG images.

Features

  • Generates bar charts in SVG format based on array data
  • Each bar represents a value (count) associated with a subject, grouped by time intervals
  • Minimal graphical representations without external dependencies or JavaScript libraries
  • Output can be passed to Blade for on-screen display
  • Built-in color scheme with automatic color generation

Security Note: For saving SVG as an image, security checks are delegated to the user. Make sure to perform all necessary security checks!

Installation

Install the package via composer:

composer require danielpetrica/svg-charts

Publish and run migrations:

php artisan vendor:publish --tag="svg-charts-migrations"
php artisan migrate

Publish the config file:

php artisan vendor:publish --tag="svg-charts-config"

Config file contents (config/svg-charts.php):

return [
    // Configuration options will go here
];

Optionally publish views:

php artisan vendor:publish --tag="svg-charts-views"

Usage

Data Format Requirements

Data must be provided as an array of associative arrays with these keys:

[
    'subject'   => (string) Subject/category name,
    'timeSlice' => (string) Time interval (e.g., "January", "2024-04"),
    'count'     => (int) The numeric value to display
]

Example dataset:

$data = [
    ['subject' => 'Product A', 'timeSlice' => 'January', 'count' => 25],
    ['subject' => 'Product B', 'timeSlice' => 'January', 'count' => 15],
    ['subject' => 'Product A', 'timeSlice' => 'February', 'count' => 30],
    ['subject' => 'Product B', 'timeSlice' => 'February', 'count' => 22],
];

Basic Usage

use DanielPetrica\SvgCharts\SvgCharts;

// Create chart instance
$chart = new SvgCharts($data, 'Monthly Sales');

// Set dimensions (width, height in pixels)
$chart->setDimensions(800, 400);

// Output to screen
echo $chart->render();

// Save to file
$chart->renderToFile('chart.svg');

Laravel Blade Integration

<div class="chart-container">
    {!! $chart->render() !!}
</div>

Customizing Colors

// Set custom colors for subjects
$chart->setColors([
    'Product A' => '#FF5733',
    'Product B' => '#33FF57'
]);

Testing

Run the test suite:

composer test

Changelog

See CHANGELOG for version history.

Contributing

Contributions welcome! See CONTRIBUTING for guidelines.

Security

Please report vulnerabilities via our security policy.

Credits

License

MIT License. See LICENSE for details.


This markdown file includes:

1. Header with badges
2. Clear feature list
3. Security notice
4. Installation instructions
5. Usage examples with code blocks
6. Data format requirements
7. Testing information
8. Standard open-source sections (Changelog, Contributing, Security, Credits, License)

The formatting uses proper markdown syntax for:
- Headers (`#`, `##`, `###`)
- Code blocks (```)
- Lists (`-`)
- Emphasis (`**`)
- Links (`[text](url)`)
- Escape characters where needed

The content is organized logically from high-level overview to specific implementation details.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固