saad-tazi/g-chart-bundle 问题修复 & 功能扩展

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

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

saad-tazi/g-chart-bundle

Composer 安装命令:

composer require saad-tazi/g-chart-bundle

包简介

A super simple Bundle that facilitate the usage of Google Chart Tool, Google Chart Image API and Google Infographics.

关键字:

README 文档

README

This is a super simple Bundle that facilitates the usage of Google Chart Tool, Google Chart Image API and Google Infographics.

It allows to render:

  • QRCode
  • Pie Chart (3 ways: canvas or svg, simple image from url, simple 3d image from url)
  • Column Chart
  • Bar Chart
  • Area Chart
  • scatter Chart
  • Combo Chart
  • Table
  • Gauge
  • Candlestick Chart
  • Map tree
  • Dynamic Icons

Added (special recommendations are below):

  • Calendar
  • Bubble Chart
  • Donut Chart (you don't really need it as you can do it with Pie Chart and configuration but it is a shortcut)
  • Gantt (beware gantt are betas)
  • Geo Chart
  • Histogram
  • Interval
  • Map
  • Org Chart
  • Sankey
  • Stepped Area Chart
  • Timeline
  • Trendline
  • Waterfall
  • Word Tree

Make sure you read the Chart Image terms and Chart tool terms before using that bundle.

It also contains some Twig extension that facilitates the integration.

Versions

You should use a different version of this bundle depending on your symfony version:

Symfony version bundle version
5+ 4.x
sf 4.4+ (< 5) 3.2.1+
sf 3.x to 4.3 3.1.1

Demo

http://blog.fruitsoftware.com/a-propos/demo-gchartbundle/

How to install it?

Thanks to AaronDDM, you can use composer to install the bundle.

composer require saad-tazi/g-chart-bundle

Or you can use the following method:

  1. Add this bundle to your vendor/ dir:

    • Using the vendors script.

      Add the following lines in your deps file:

      [SaadTaziGChartBundle]
          git=git://github.com/saadtazi/SaadTaziGChartBundle.git
          target=/bundles/SaadTazi/GChartBundle
      

      Run the vendors script:

      ./bin/vendors install
      
    • Using git submodules.

      $ git submodule add git://github.com/saadtazi/SaadTaziGChartBundle.git vendor/bundles/SaadTazi/GChartBundle
      
  2. Add the SaadTazi namespace to your autoloader:

          // app/autoload.php
          $loader->registerNamespaces(array(
                'SaadTazi' => __DIR__.'/../vendor/bundles',
                // your other namespaces
          ));
  1. Add this bundle to your application's kernel:
          // app/ApplicationKernel.php
          public function registerBundles()
          {
              return array(
                  // ...
                  new SaadTazi\GChartBundle\SaadTaziGChartBundle(),
                  // ...
              );
          }

Demo pages

This is optional: If you want to see the demo page, add the following to your routing.yml:

    _demo:
        resource: "@SaadTaziGChartBundle/Resources/config/routing.yml"
        type:     yaml
        prefix:   /gchart

You should have templating installed (php ../composer.phar require templating) and should have activated it in `config/packages/framework.yml:

framework:
    templating:
        engines: ['twig']

Then you should be able to go to http://your.site.com/gchart/demo

Don't forget to include the required javascript in your layout, for example:

        <script type="text/javascript">
            // adds the package you need. See https://developers.google.com/chart/interactive/docs/basic_load_libs
            google.charts.load('current', {packages:["corechart", 'table', 'gauge']});
        </script>

How to use it?

Mmm, please check the Controller\DemoController to see how to build DataTable, and Resources\views\Demo\demo.html.twig

Notes

I implemented almost all the corechart chart types from the Google Chart Tool. But I only implemented 3 Google Chart Image types, because (they are ugly and) almost all of them can be built using the Google Chart Tool. From the Visualization, I only implemented the marker.

Ohh, please feel free to fork, add to it and send me pull requests!

Note: You don't have to use the Twig functions: you can use the php classes (in DataTable and or in Chart). But you will probably find it a little bit "painful".

Using the added charts

Calendar, Interval and gantt (charts needing dates as datas) :

These are special charts see https://developers.google.com/chart/interactive/docs/gallery/calendar#a-simple-example

These charts needs javascript Date Objects in first column.

As the Js Date Object need to be written (in json) like :


    [ new Date(2012, 3, 13), 37032 ],
    [ new Date(2012, 3, 14), 38024 ],
    [ new Date(2012, 3, 15), 38024 ],
    [ new Date(2012, 3, 16), 38108 ],
    [ new Date(2012, 3, 17), 38229 ],

I encountered issues with PHP and Json_encode. To avoid this you had to make your datas like this :

    $datas = array(
        array('date' => DateTime::createFromFormat ( 'Y-m-d' , "2016-03-01"), 'md' => 3),
        array('date' => DateTime::createFromFormat ( 'Y-m-d' , "2016-03-02"), 'md' => 5),
        array('date' => DateTime::createFromFormat ( 'Y-m-d' , "2016-03-03"), 'md' => 1),
        array('date' => DateTime::createFromFormat ( 'Y-m-d' , "2016-03-04"), 'md' => 9),
        array('date' => DateTime::createFromFormat ( 'Y-m-d' , "2016-03-10"), 'md' => 24),
    );
    $res = new DataTable();
    $res->addColumn('date', 'Date', 'date');
    $res->addColumn('my_datas', 'My Datas', 'number');
    foreach($datas as $data) {
        // js month starts at 0 for Jan !
        $date => $data['date']->format("Y, ").(intval($data['date']->format("m"))-1).$data['date']->format(", d");
        $res->addRow([['v' => "new Date[[[{$date}]]]"], ['v' => $data['md']]);
    }

It gives the following json (don't get scared by the '"new Date[[[' and ']]]"', they are substituded when needed in the twig) :


    [ "new Date[[[2016, 2, 1]]]", 3 ],....

You can had a Tooltip to your datas by using this code :

    // 'role_tooltip' must be written as i showed because it makes all the magic.
    $res->addColumn('role_tooltip', 'Tooltip', 'string');

    // ....

    foreach($datas as $data) {
        // js month starts at 0 for Jan !
        $date => $data['date']->format("Y, ").(intval($data['date']->format("m"))-1).$data['date']->format(", d");
        $res->addRow([['v' => "new Date[[[{$date}]]]"], ['v' => $data['md'], ['v' => "My wonderfull Tooltip for this row"]]);
    }

Support for events

You can define your own callback functions and associate it to the corresponding chart event like this:

    <div id="calChart">&nbsp;</div>
    <script>
        $(function() {
            var myMo = function (ee) {
                console.log('Mouse over');
            }
            var myMou = function (ee) {
                console.log('Mouse out');
            }
            var myR = function () {
                console.log('Ready');
            }

            {{ gchart_calendar(calDatas, 'calChart', 950, 180, 'My cal datas', {tooltip:{isHtml: true,trigger: 'selection'}},
                [{'eventName': 'ready', 'callbackFunc': 'myR'},
                 {'eventName': 'onmouseover', 'callbackFunc': 'myMo'},
                 {'eventName': 'onmouseout', 'callbackFunc': 'myMou'},
          ]) }}
        });
    </script>

Have fun with those mods ;-)

Mods

2012-03-20

  • added composer support (thanks to AaronDDM)

2011-10-23

  • removed jQuery dependency (and div output - needs to be done "manually" now... Provides more control)

2011-09-22

  • zero value bug fix

2011-09-06

  • Added DataTable::toStrictArray() that checks array keys (ticket #1)

2011-06-23

  • Initial commit

saad-tazi/g-chart-bundle 适用场景与选型建议

saad-tazi/g-chart-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 168.02k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2012 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「google」 「chart」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 saad-tazi/g-chart-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 saad-tazi/g-chart-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 saad-tazi/g-chart-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-03-21