Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
應用chartJS繪圖的類別.
29
備註:
30
無.
31
*/
32
class chartJS{
226 liveuser 33
 
3 liveuser 34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
47
	public function __call($method,$arguments){
226 liveuser 48
 
3 liveuser 49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
226 liveuser 51
 
3 liveuser 52
		#設置執行不正常
53
		$result["status"]="false";
226 liveuser 54
 
3 liveuser 55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 57
 
3 liveuser 58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
226 liveuser 60
 
3 liveuser 61
		#回傳結果
62
		return $result;
226 liveuser 63
 
3 liveuser 64
		}#function __call end
226 liveuser 65
 
3 liveuser 66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
226 liveuser 80
 
3 liveuser 81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
226 liveuser 83
 
3 liveuser 84
		#設置執行不正常
85
		$result["status"]="false";
226 liveuser 86
 
3 liveuser 87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 89
 
3 liveuser 90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
226 liveuser 92
 
3 liveuser 93
		#回傳結果
94
		return $result;
226 liveuser 95
 
3 liveuser 96
		}#function __callStatic end
226 liveuser 97
 
3 liveuser 98
	/*
99
	#函式說明:
100
	#匯入chartJS的函式庫.
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
103
	#$result["error"],錯誤訊息.
104
	#$result["content"],語法.
105
	#$result["function"],當前執行的函數名稱.
106
	#必填參數:
107
	#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
108
	$conf["libAddr"]="";
109
	#可省略參數:
110
	#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
111
	#$conf["fileArgu"]=__FILE__;
112
	#參考資料:
113
	#無.
114
	#備註:
115
	#無.
116
	*/
117
	public static function importLib(&$conf){
226 liveuser 118
 
3 liveuser 119
		#初始化要回傳的內容
120
		$result=array();
226 liveuser 121
 
3 liveuser 122
		#取得當前執行的函數名稱
123
		$result["function"]=__FUNCTION__;
226 liveuser 124
 
3 liveuser 125
		#初始化要回傳的語法
126
		$result["content"]="";
226 liveuser 127
 
3 liveuser 128
		#如果沒有參數
129
		if(func_num_args()==0){
226 liveuser 130
 
3 liveuser 131
			#設置執行失敗
132
			$result["status"]="false";
226 liveuser 133
 
3 liveuser 134
			#設置執行錯誤訊息
135
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 136
 
3 liveuser 137
			#回傳結果
138
			return $result;
226 liveuser 139
 
3 liveuser 140
			}#if end
226 liveuser 141
 
3 liveuser 142
		#取得參數
143
		$result["argu"]=$conf;
226 liveuser 144
 
3 liveuser 145
		#如果 $conf 不為陣列
146
		if(gettype($conf)!="array"){
226 liveuser 147
 
3 liveuser 148
			#設置執行失敗
149
			$result["status"]="false";
226 liveuser 150
 
3 liveuser 151
			#設置執行錯誤訊息
152
			$result["error"][]="\$conf變數須為陣列形態";
153
 
154
			#如果傳入的參數為 null
155
			if($conf==null){
226 liveuser 156
 
3 liveuser 157
				#設置執行錯誤訊息
158
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 159
 
3 liveuser 160
				}#if end
161
 
162
			#回傳結果
163
			return $result;
226 liveuser 164
 
3 liveuser 165
			}#if end
226 liveuser 166
 
3 liveuser 167
		#檢查參數
168
		#函式說明:
169
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
170
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
171
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
172
		#$result["function"],當前執行的函式名稱.
173
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
174
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
175
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
176
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
177
		#必填寫的參數:
178
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
179
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
180
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
181
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("libAddr");
226 liveuser 182
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 183
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
184
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
185
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
186
		#可以省略的參數:
187
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
188
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
189
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
190
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu");
226 liveuser 191
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 192
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
193
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
194
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
195
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
196
		#$conf["arrayCountEqualCheck"][]=array();
197
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
198
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 199
 
3 liveuser 200
		#如果檢查參數失敗
201
		if($checkResult["status"]=="false"){
226 liveuser 202
 
3 liveuser 203
			#設置執行失敗
204
			$result["status"]="false";
226 liveuser 205
 
3 liveuser 206
			#設置錯誤訊息
207
			$result["error"]=$checkResult;
226 liveuser 208
 
3 liveuser 209
			#回傳結果
210
			return $result;
226 liveuser 211
 
3 liveuser 212
			}#if end
226 liveuser 213
 
3 liveuser 214
		#如果檢查參數不通過
215
		if($checkResult["passed"]=="false"){
226 liveuser 216
 
3 liveuser 217
			#設置執行失敗
218
			$result["status"]="false";
226 liveuser 219
 
3 liveuser 220
			#設置錯誤訊息
221
			$result["error"]=$checkResult;
226 liveuser 222
 
3 liveuser 223
			#回傳結果
224
			return $result;
226 liveuser 225
 
3 liveuser 226
			}#if end
226 liveuser 227
 
228
		#匯入 $conf["libAddr"] js檔案
3 liveuser 229
		#函式說明:
226 liveuser 230
		#匯入js檔案
3 liveuser 231
		#回傳結果:
232
		#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
233
		#$result["functin"],字串,當前函數的名稱.
234
		#$result["error"],陣列,錯訊訊息.
235
		#$result["content"],字串,匯入css樣式的語法.
236
		#必填參數:
237
		#$conf["jsFileLocation"],陣列字串,多個js檔案的位置與名稱,每個元素代表一個js檔案的位置,js副檔名會自動補上.
238
		$conf["javaScript::import"]["jsFileLocation"]=array($conf["libAddr"]);
239
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
240
		$conf["javaScript::import"]["fileArgu"]=$conf["fileArgu"];
241
		#可省略參數:
242
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,於設為"true".
243
		#$conf["userDir"]="true";
244
		#參考資料:
245
		#php於設常數=>http://php.net/manual/zh/language.constants.predefined.php
246
		$import=javaScript::import($conf["javaScript::import"]);
247
		unset($conf["javaScript::import"]);
226 liveuser 248
 
3 liveuser 249
		#var_dump($import);
226 liveuser 250
 
3 liveuser 251
		#如果建立匯入js檔案的語法失敗
252
		if($import["status"]=="false"){
226 liveuser 253
 
3 liveuser 254
			#設置執行失敗
255
			$result["status"]="false";
226 liveuser 256
 
3 liveuser 257
			#設置錯誤訊息
258
			$result["error"]=$import;
226 liveuser 259
 
3 liveuser 260
			#回傳結果
261
			return $result;
226 liveuser 262
 
3 liveuser 263
			}#if end
226 liveuser 264
 
3 liveuser 265
		#取得js語法
266
		$result["content"]=$import["content"];
226 liveuser 267
 
3 liveuser 268
		#設置執行正常
269
		$result["status"]="true";
226 liveuser 270
 
3 liveuser 271
		#回傳結果
272
		return $result;
226 liveuser 273
 
3 liveuser 274
		}#function importLib end
226 liveuser 275
 
3 liveuser 276
	/*
277
	#函式說明:
278
	#顯示長條圖的demo.
279
	#回傳結果:
280
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
281
	#$result["error"],錯誤訊息.
282
	#$result["content"],語法.
283
	#$result["function"],當前執行的函數名稱.
284
	#必填參數:
285
	#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
286
	$conf["libAddr"]="";
287
	#可省略參數:
288
	#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
289
	#$conf["fileArgu"]=__FILE__;
290
	#參考資料:
291
	#Creating a Chart=>http://www.chartjs.org/docs/latest/
292
	#備註:
293
	#無.
294
	*/
295
	public static function barDemo(&$conf=array()){
226 liveuser 296
 
3 liveuser 297
		#初始化要回傳的內容
298
		$result=array();
226 liveuser 299
 
3 liveuser 300
		#取得當前執行的函數名稱
301
		$result["function"]=__FUNCTION__;
226 liveuser 302
 
3 liveuser 303
		#初始化要回傳的語法
304
		$result["content"]="";
226 liveuser 305
 
3 liveuser 306
		#如果沒有參數
307
		if(func_num_args()==0){
226 liveuser 308
 
3 liveuser 309
			#設置執行失敗
310
			$result["status"]="false";
226 liveuser 311
 
3 liveuser 312
			#設置執行錯誤訊息
313
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 314
 
3 liveuser 315
			#回傳結果
316
			return $result;
226 liveuser 317
 
3 liveuser 318
			}#if end
226 liveuser 319
 
3 liveuser 320
		#取得參數
321
		$result["argu"]=$conf;
226 liveuser 322
 
3 liveuser 323
		#如果 $conf 不為陣列
324
		if(gettype($conf)!="array"){
226 liveuser 325
 
3 liveuser 326
			#設置執行失敗
327
			$result["status"]="false";
226 liveuser 328
 
3 liveuser 329
			#設置執行錯誤訊息
330
			$result["error"][]="\$conf變數須為陣列形態";
331
 
332
			#如果傳入的參數為 null
333
			if($conf==null){
226 liveuser 334
 
3 liveuser 335
				#設置執行錯誤訊息
336
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 337
 
3 liveuser 338
				}#if end
339
 
340
			#回傳結果
341
			return $result;
226 liveuser 342
 
3 liveuser 343
			}#if end
226 liveuser 344
 
3 liveuser 345
		#檢查參數
346
		#函式說明:
347
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
348
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
349
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
350
		#$result["function"],當前執行的函式名稱.
351
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
352
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
353
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
354
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
355
		#必填寫的參數:
356
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
357
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
358
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
359
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("libAddr");
226 liveuser 360
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 361
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
362
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
363
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
364
		#可以省略的參數:
365
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
366
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
367
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
368
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu");
226 liveuser 369
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 370
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
371
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
372
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
373
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
374
		#$conf["arrayCountEqualCheck"][]=array();
375
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
376
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 377
 
3 liveuser 378
		#如果檢查參數失敗
379
		if($checkResult["status"]=="false"){
226 liveuser 380
 
3 liveuser 381
			#設置執行失敗
382
			$result["status"]="false";
226 liveuser 383
 
3 liveuser 384
			#設置錯誤訊息
385
			$result["error"]=$checkResult;
226 liveuser 386
 
3 liveuser 387
			#回傳結果
388
			return $result;
226 liveuser 389
 
3 liveuser 390
			}#if end
226 liveuser 391
 
3 liveuser 392
		#如果檢查參數不通過
393
		if($checkResult["passed"]=="false"){
226 liveuser 394
 
3 liveuser 395
			#設置執行失敗
396
			$result["status"]="false";
226 liveuser 397
 
3 liveuser 398
			#設置錯誤訊息
399
			$result["error"]=$checkResult;
226 liveuser 400
 
3 liveuser 401
			#回傳結果
402
			return $result;
226 liveuser 403
 
3 liveuser 404
			}#if end
226 liveuser 405
 
3 liveuser 406
		#demo用的目標
407
		$demoTarget="<canvas id=\"myChart\" width=\"400\" height=\"400\"></canvas>";
226 liveuser 408
 
3 liveuser 409
		#函式說明:
410
		#匯入chartJS的函式庫.
411
		#回傳結果:
412
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
413
		#$result["error"],錯誤訊息.
414
		#$result["content"],語法.
415
		#$result["function"],當前執行的函數名稱.
416
		#必填參數:
417
		#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
418
		$conf["chartJS::importLib"]["libAddr"]=$conf["libAddr"];
419
		#可省略參數:
420
		#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
421
		$conf["chartJS::importLib"]["fileArgu"]=$conf["fileArgu"];
422
		$importLib=chartJS::importLib($conf["chartJS::importLib"]);
423
		unset($conf["chartJS::importLib"]);
226 liveuser 424
 
3 liveuser 425
		#如果建立匯入 chart js lib 的語法失敗
426
		if($importLib["status"]=="false"){
226 liveuser 427
 
3 liveuser 428
			#設置執行失敗
429
			$result["status"]="false";
226 liveuser 430
 
3 liveuser 431
			#設置錯誤訊息
432
			$result["error"]=$importLib;
226 liveuser 433
 
3 liveuser 434
			#回傳結果
435
			return $result;
226 liveuser 436
 
3 liveuser 437
			}#if end
226 liveuser 438
 
3 liveuser 439
		#取得匯入chart js的語法
440
		$result["content"]=$result["content"].$importLib["content"];
226 liveuser 441
 
3 liveuser 442
		#涵式說明:
443
		#將要執行的script語法透過該函式執行
444
		#回傳結果:
445
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
446
		#$result["error"],錯誤訊息陣列
447
		#$result["function"],當前執行的函數名稱
448
		#$result["content"],要執行的javaScript語法
449
		#必填的參數:
450
		#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
451
		$conf["javaScript::toScript"]["script"]="
452
			var ctx = document.getElementById(\"myChart\").getContext('2d');
226 liveuser 453
			var myChart = new Chart(ctx,
3 liveuser 454
			{
455
				type: 'bar',
456
				data: {
457
					labels: [\"Red\", \"Blue\", \"Yellow\", \"Green\", \"Purple\", \"Orange\"],
458
					datasets: [{
459
						label: '# of Votes',
460
						data: [12, 19, 3, 5, 2, 3],
461
						backgroundColor: [
462
							'rgba(255, 99, 132, 0.2)',
463
							'rgba(54, 162, 235, 0.2)',
464
							'rgba(255, 206, 86, 0.2)',
465
							'rgba(75, 192, 192, 0.2)',
466
							'rgba(153, 102, 255, 0.2)',
467
							'rgba(255, 159, 64, 0.2)'
468
						],
469
						borderColor: [
470
							'rgba(255,99,132,1)',
471
							'rgba(54, 162, 235, 1)',
472
							'rgba(255, 206, 86, 1)',
473
							'rgba(75, 192, 192, 1)',
474
							'rgba(153, 102, 255, 1)',
475
							'rgba(255, 159, 64, 1)'
476
						],
477
						borderWidth: 1
478
					}]
479
				},
480
				options: {
481
					scales: {
482
						yAxes: [{
483
							ticks: {
484
								beginAtZero:true
485
							}
486
						}]
487
					}
488
				}
489
			});
490
			";
491
		$toScript=javaScript::toScript($conf["javaScript::toScript"]);
492
		unset($conf["javaScript::toScript"]);
226 liveuser 493
 
3 liveuser 494
		#如果轉換成js語法失敗
495
		if($toScript["status"]=="false"){
226 liveuser 496
 
3 liveuser 497
			#設置執行失敗
498
			$result["status"]="false";
226 liveuser 499
 
3 liveuser 500
			#設置錯誤訊息
501
			$result["error"]=$toScript;
226 liveuser 502
 
3 liveuser 503
			#回傳結果
504
			return $result;
226 liveuser 505
 
3 liveuser 506
			}#if end
226 liveuser 507
 
3 liveuser 508
		#取得使用chart js的語法
509
		$result["content"]=$result["content"].$demoTarget.$toScript["content"];
226 liveuser 510
 
3 liveuser 511
		#設置執行正常
512
		$result["status"]="true";
226 liveuser 513
 
3 liveuser 514
		#回傳結果
515
		return $result;
226 liveuser 516
 
3 liveuser 517
		}#function barDemo end
226 liveuser 518
 
3 liveuser 519
	/*
520
	#函式說明:
521
	#將數據用長條圖表示.
522
	#回傳結果:
523
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
524
	#$result["error"],錯誤訊息.
525
	#$result["content"],語法.
526
	#$result["function"],當前執行的函數名稱.
527
	#必填參數:
528
	#$conf["libAddr"],字串,爲chartJS的位置,js附檔名會自動補上.
529
	$conf["libAddr"]="";
530
	#$conf["data"],字串,要繪製的數據,例如:"2017/07/09 508.25 2017/07/16 1365 2017/07/23 949 2017/07/30 455 2017/08/06 917 2017/08/13 0".
226 liveuser 531
	$conf["data"]="";
3 liveuser 532
	#$conf["canvasId"],字串,為要繪製圖表到哪個canvas元素的id.
533
	$conf["canvasId"]="";
534
	#$conf["title"],字串,圖表的標題.
535
	$conf["title"]="";
536
	#conf["yTitle"],字串,y軸標題.
537
	$conf["yTitle"]="";
538
	#conf["xTitle"],字串,x軸標題.
539
	$conf["xTitle"]="";
540
	#可省略參數:
541
	#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
542
	#$conf["fileArgu"]=__FILE__;
543
	#$conf["dataUnit"],字串,數據的單位,預設為"number";
544
	#$conf["dataUnit"]="number";
545
	#$conf["yTcolor"],字串,y軸標題顏色與透明度,例如:"0,0,255,0.8"就代表紅光0,綠光0,藍光255,透明度0.2.
546
	#$conf["yTcolor"]="";
547
	#$conf["xTcolor"],字串,x軸標題顏色與透明度,例如:"0,0,255,0.8"就代表紅光0,綠光0,藍光255,透明度0.2.
548
	#$conf["xTcolor"]="";
549
	#參考資料:
550
	#Creating a Chart=>http://www.chartjs.org/docs/latest/
551
	#備註:
552
	#無.
553
	*/
554
	public static function bar(&$conf=array()){
226 liveuser 555
 
3 liveuser 556
		#初始化要回傳的內容
557
		$result=array();
226 liveuser 558
 
3 liveuser 559
		#取得當前執行的函數名稱
560
		$result["function"]=__FUNCTION__;
226 liveuser 561
 
3 liveuser 562
		#初始化要回傳的語法
563
		$result["content"]="";
226 liveuser 564
 
3 liveuser 565
		#如果沒有參數
566
		if(func_num_args()==0){
226 liveuser 567
 
3 liveuser 568
			#設置執行失敗
569
			$result["status"]="false";
226 liveuser 570
 
3 liveuser 571
			#設置執行錯誤訊息
572
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 573
 
3 liveuser 574
			#回傳結果
575
			return $result;
226 liveuser 576
 
3 liveuser 577
			}#if end
226 liveuser 578
 
3 liveuser 579
		#取得參數
580
		$result["argu"]=$conf;
226 liveuser 581
 
3 liveuser 582
		#如果 $conf 不為陣列
583
		if(gettype($conf)!="array"){
226 liveuser 584
 
3 liveuser 585
			#設置執行失敗
586
			$result["status"]="false";
226 liveuser 587
 
3 liveuser 588
			#設置執行錯誤訊息
589
			$result["error"][]="\$conf變數須為陣列形態";
590
 
591
			#如果傳入的參數為 null
592
			if($conf==null){
226 liveuser 593
 
3 liveuser 594
				#設置執行錯誤訊息
595
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 596
 
3 liveuser 597
				}#if end
598
 
599
			#回傳結果
600
			return $result;
226 liveuser 601
 
3 liveuser 602
			}#if end
226 liveuser 603
 
3 liveuser 604
		#檢查參數
605
		#函式說明:
606
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
607
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
608
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
609
		#$result["function"],當前執行的函式名稱.
610
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
611
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
612
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
613
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
614
		#必填寫的參數:
615
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
616
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
617
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
618
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("libAddr","data","canvasId","title","xTitle","yTitle");
226 liveuser 619
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 620
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string","string",);
621
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
622
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
623
		#可以省略的參數:
624
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
625
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
626
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
627
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","dataUnit","xTcolor","yTcolor");
226 liveuser 628
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 629
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
630
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
631
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,"number","0,0,255,0.8","0,0,255,0.8");
632
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
633
		#$conf["arrayCountEqualCheck"][]=array();
634
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
635
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 636
 
3 liveuser 637
		#如果檢查參數失敗
638
		if($checkResult["status"]=="false"){
226 liveuser 639
 
3 liveuser 640
			#設置執行失敗
641
			$result["status"]="false";
226 liveuser 642
 
3 liveuser 643
			#設置錯誤訊息
644
			$result["error"]=$checkResult;
226 liveuser 645
 
3 liveuser 646
			#回傳結果
647
			return $result;
226 liveuser 648
 
3 liveuser 649
			}#if end
226 liveuser 650
 
3 liveuser 651
		#如果檢查參數不通過
652
		if($checkResult["passed"]=="false"){
226 liveuser 653
 
3 liveuser 654
			#設置執行失敗
655
			$result["status"]="false";
226 liveuser 656
 
3 liveuser 657
			#設置錯誤訊息
658
			$result["error"]=$checkResult;
226 liveuser 659
 
3 liveuser 660
			#回傳結果
661
			return $result;
226 liveuser 662
 
3 liveuser 663
			}#if end
226 liveuser 664
 
3 liveuser 665
		#函式說明:
666
		#匯入chartJS的函式庫.
667
		#回傳結果:
668
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
669
		#$result["error"],錯誤訊息.
670
		#$result["content"],語法.
671
		#$result["function"],當前執行的函數名稱.
672
		#必填參數:
673
		#$conf["libAddr"],字串,爲ckfEditor套件的網路位置,js附檔名會自動補上.
674
		$conf["chartJS::importLib"]["libAddr"]=$conf["libAddr"];
675
		#可省略參數:
676
		#$conf["fileArgu"],字串,為當前檔案的路徑,預設為__FILE__.
677
		$conf["chartJS::importLib"]["fileArgu"]=$conf["fileArgu"];
678
		$importLib=chartJS::importLib($conf["chartJS::importLib"]);
679
		unset($conf["chartJS::importLib"]);
226 liveuser 680
 
3 liveuser 681
		#如果建立匯入 chart js lib 的語法失敗
682
		if($importLib["status"]=="false"){
226 liveuser 683
 
3 liveuser 684
			#設置執行失敗
685
			$result["status"]="false";
226 liveuser 686
 
3 liveuser 687
			#設置錯誤訊息
688
			$result["error"]=$importLib;
226 liveuser 689
 
3 liveuser 690
			#回傳結果
691
			return $result;
226 liveuser 692
 
3 liveuser 693
			}#if end
226 liveuser 694
 
3 liveuser 695
		#取得匯入chart js的語法
696
		$result["content"]=$result["content"].$importLib["content"];
226 liveuser 697
 
3 liveuser 698
		#用空格分割
699
		$dataSet=explode(' ',$conf["data"]);
226 liveuser 700
 
3 liveuser 701
		#初始化儲存x軸標題的陣列
702
		$lables=array();
226 liveuser 703
 
3 liveuser 704
		#初始化儲存y軸數據的陣列
705
		$values=array();
226 liveuser 706
 
3 liveuser 707
		#兩兩一對
708
		for($i=0;$i<count($dataSet);$i=$i+2){
226 liveuser 709
 
3 liveuser 710
			#取得x軸項目
711
			$lables[]=$dataSet[$i];
226 liveuser 712
 
3 liveuser 713
			#取得y軸項目
714
			$values[]=$dataSet[$i+1];
226 liveuser 715
 
716
			}#for end
717
 
3 liveuser 718
		#涵式說明:
719
		#將要執行的script語法透過該函式執行
720
		#回傳結果:
721
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
722
		#$result["error"],錯誤訊息陣列
723
		#$result["function"],當前執行的函數名稱
724
		#$result["content"],要執行的javaScript語法
725
		#必填的參數:
726
		#$conf["script"],字串,要執行的javaScript語法,標籤「<script></script>」會自動補上.
727
		$conf["javaScript::toScript"]["script"]="
728
			var ctx = document.getElementById(\"".$conf["canvasId"]."\").getContext('2d');
226 liveuser 729
			var myChart = new Chart(ctx,
3 liveuser 730
			{
731
				type: 'bar',
732
				data: {
733
					labels: ".json_encode($lables).",
734
					datasets: [{
735
						label: '# of ".$conf["dataUnit"]."',
736
						data: ".json_encode($values).",
737
						backgroundColor: [
738
							'rgba(255, 99, 132, 0.2)',
739
							'rgba(54, 162, 235, 0.2)',
740
							'rgba(255, 206, 86, 0.2)',
741
							'rgba(75, 192, 192, 0.2)',
742
							'rgba(153, 102, 255, 0.2)',
743
							'rgba(255, 159, 64, 0.2)'
744
						],
745
						borderColor: [
746
							'rgba(255,99,132,1)',
747
							'rgba(54, 162, 235, 1)',
748
							'rgba(255, 206, 86, 1)',
749
							'rgba(75, 192, 192, 1)',
750
							'rgba(153, 102, 255, 1)',
751
							'rgba(255, 159, 64, 1)'
752
						],
753
						borderWidth: 1
754
					}]
755
				},
226 liveuser 756
				options:
3 liveuser 757
				{
226 liveuser 758
					scales:
3 liveuser 759
					{
226 liveuser 760
						yAxes:
3 liveuser 761
						[{
226 liveuser 762
							ticks:
3 liveuser 763
							{
764
								beginAtZero:true
226 liveuser 765
							},
766
							scaleLabel:
3 liveuser 767
							{
768
								display: true,
769
								labelString: '".$conf["yTitle"]."',
770
								fontColor:'rgba(".$conf["yTcolor"].")',
226 liveuser 771
							}
3 liveuser 772
						}],
226 liveuser 773
						xAxes:
3 liveuser 774
						[{
226 liveuser 775
							scaleLabel:
3 liveuser 776
							{
777
								display: true,
778
								labelString: '".$conf["xTitle"]."',
779
								fontColor:'rgba(".$conf["yTcolor"].")',
226 liveuser 780
							}
3 liveuser 781
						}]
782
					},
226 liveuser 783
					title:
3 liveuser 784
					{
785
						display: true,
786
						text: '".$conf["title"]."'
787
					},
226 liveuser 788
					legend:
3 liveuser 789
					{
790
						//disable class label
791
						display: false
792
					},
793
				}
794
			});
226 liveuser 795
			";
3 liveuser 796
		$toScript=javaScript::toScript($conf["javaScript::toScript"]);
797
		unset($conf["javaScript::toScript"]);
226 liveuser 798
 
3 liveuser 799
		#如果轉換成js語法失敗
800
		if($toScript["status"]=="false"){
226 liveuser 801
 
3 liveuser 802
			#設置執行失敗
803
			$result["status"]="false";
226 liveuser 804
 
3 liveuser 805
			#設置錯誤訊息
806
			$result["error"]=$toScript;
226 liveuser 807
 
3 liveuser 808
			#回傳結果
809
			return $result;
226 liveuser 810
 
3 liveuser 811
			}#if end
226 liveuser 812
 
3 liveuser 813
		#取得使用chart js的語法
814
		$result["content"]=$result["content"].$toScript["content"];
226 liveuser 815
 
3 liveuser 816
		#設置執行正常
817
		$result["status"]="true";
226 liveuser 818
 
3 liveuser 819
		#回傳結果
820
		return $result;
226 liveuser 821
 
3 liveuser 822
		}#function barDemo end
226 liveuser 823
 
3 liveuser 824
	}#class chartJS end
825
 
826
?>