xanpena/svg-chart-builder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

xanpena/svg-chart-builder

最新稳定版本:1.3

Composer 安装命令:

composer require xanpena/svg-chart-builder

包简介

PHP SVG Chart Builder

README 文档

README

SVGChartBuilder is a PHP library that allows you to generate SVG-based charts for use in your backend applications.

Requirements

PHP 8.0 or later

Installation

You can install SVGChartBuilder via Composer:

To install using Composer, run the following command in your terminal:

    composer require xanpena/svg-chart-builder

Usage

SVGChartBuilder provides several types of charts that you can create:

Example

To create a bar chart, use the following code:

  • Tipo Bar chart
use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'axisColors' => [
        'x' => 'red',
        'y' => 'blue'
    ],
    'labelsColor' => 'orange',
    'dataColor' => 'white',
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_BAR, $data, $options);
$svg = $chartBuilder->create();
echo $svg;
  • Tipo Horizontal bar chart
use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'axisColors' => [
        'x' => 'red',
        'y' => 'blue'
    ],
    'labelsColor' => 'orange',
    'dataColor' => 'white',
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_HORIZONTALBAR, $data, $options);
$svg = $chartBuilder->create();
echo $svg;
  • Tipo Doughnut chart
use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'labelsColor' => 'white'
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_DOUGHNUT, $data, $options);
$svg = $chartBuilder->create();
echo $svg;
  • Tipo Pie chart
use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'labelsColor' => 'white'
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_PIE, $data, $options);
$svg = $chartBuilder->create();
echo $svg;
  • Tipo Line chart
use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    'math' => [
        11,
        17,
        15,
        // ... other data ...
    ],
    'literature' => [
        21,
        21,
        23,
        // ... other data ...
    ],
    'english' => [
        14,
        9,
        18,
        // ... other data ...
    ]
    // ... other data ...
];

$options = [
    'labels' => [
        '2020/2021',
        '2021/2022',
        '2023/2024',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'axisColors' => [
        'x' => 'red',
        'y' => 'blue'
    ],
    'labelsColor' => 'orange',
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_LINE, $data, $options);
$svg = $chartBuilder->create();
echo $svg;

Chart Types

SVGChartBuilder supports the following chart types:

SVGChartBuilder::BAR_CHART: Bar chart
SVGChartBuilder::HORIZONTALBAR_CHART: Horizontal bar chart
SVGChartBuilder::DOUGHNUT_CHART: Doughnut chart
SVGChartBuilder::PIE_CHART: Pie chart
SVGChartBuilder::CHART_TYPE_LINE: Line chart

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please using the issue tracker.

Credits

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固