定制 shahariaazam/google-charts 二次开发

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

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

shahariaazam/google-charts

Composer 安装命令:

composer require shahariaazam/google-charts

包简介

A CakePHP plugin for creating Google Charts.

README 文档

README

This is an attempt to build a multipurpose CakePHP plugin to interface with the Google Charts Javascript API.

I welcome any assistance for enhancing / fixing issues with this plugin!

Requirements

  • CakePHP 2.0+
  • PHP 5.3+

Currently, this plugin only works with 2D charts (line, bar, pie, etc.)

Installation

Clone this repository or download a copy to the CakePHP or your application's Plugins directory. Be sure to name the folder GoogleCharts.

Be sure that you load plugins in your application's bootstrap file:

CakePlugin::loadAll();

Usage

There are two phases to using this plugin:

  1. Building the data.
  2. Building the Javascript for display.

##Controller Setup & Actions##

Include the GoogleCharts class in your controller: App::uses('GoogleCharts', 'GoogleCharts.Lib');. This class will help build the data for your charts.

Also, include the GoogleChartsHelper class in your controller so we can use it in the view: public $helpers = array('GoogleCharts.GoogleCharts');

The GoogleCharts class is meant to mimic the properties needed per the Google Chart API. Each chart that you want to display on your page needs it's own instance of this class. Once you have prepared the class with settings and data, then set for your view to pass to the View Helper.

//Get data from model
//Get the last 10 rounds for score graph
$rounds = $this->Round->find(
	'all',
	array(
		'conditions' => array(
			'Round.user_id' => $this->Auth->user('id')
		),
		'order' => array('Round.event_date' => 'ASC'),
		'limit' => 10,
		'fields' => array(
			'Round.score',
			'Round.event_date'
		)
	)
);

//Setup data for chart
$chart = new GoogleCharts();

$chart->type("LineChart");	
	//Options array holds all options for Chart API
	$chart->options(array('title' => "Recent Scores")); 
	$chart->columns(array(
		//Each column key should correspond to a field in your data array
		'event_date' => array(
			//Tells the chart what type of data this is
			'type' => 'string',		
			//The chart label for this column			
			'label' => 'Date'
		),
		'score' => array(
			'type' => 'number',
			'label' => 'Score',
			//Optional NumberFormat pattern
			'format' => '#,###'
		)
	));

//Loop through our data and creates data rows
//Data will be added to rows based on the column keys above (event_date, score).
//If there are missing fields in your data or the keys do not match, then this will not work.
foreach($model as $round){
	$chart->addRow($round['Round']);
}

//You can also use this way to loop through data and creates data rows: 
foreach($rounds as $row){
	//$chart->addRow(array('event_date' => $row['Model']['field1'], 'score' => $row['Model']['field2']));
	$chart->addRow(array('event_date' => $row['Round']['event_date'], 'score' => $row['Round']['score']));
}


//You can also manually add rows: 
$chart->addRow(array('event_date' => '1/1/2012', 'score' => 55));

//Set the chart for your view
$this->set(compact('chart'));

##View##

  1. Create a div for the chart.
    • You can use the default chart_div as the id or set your own.
    • If you set your own div ID (or need to for more than one chart) then update your chart object: <?php $chart->div('div_id');?>
  2. Use the GoogleChartsHelper to display your chart(s).
    • <div id="chart_div"><?php $this->GoogleCharts->createJsChart($chart);?></div>

License

Copyright 2012 Scott Harwell

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

shahariaazam/google-charts 适用场景与选型建议

shahariaazam/google-charts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 12 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 shahariaazam/google-charts 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2014-12-03