001package org.opengion.hayabusa.taglib; 002 003import java.util.ArrayList; 004import java.util.Arrays; 005import java.util.List; 006import java.util.regex.Matcher; 007import java.util.regex.Pattern; 008 009import org.opengion.hayabusa.common.HybsSystem; 010import org.opengion.hayabusa.common.HybsSystemException; 011import org.opengion.hayabusa.db.DBTableModel; 012import org.opengion.hayabusa.html.ViewForm; 013import org.opengion.hayabusa.html.ViewFormFactory; 014import org.opengion.hayabusa.io.JsChartData; 015 016/** 017 * JsChart は、JavascriptのjsChart用のスクリプトを出力するクラスです。 018 * 複数の JsChartData オブジェクトを合成することも、ここで行っています。 019 * ChartJSを利用しているため、標準属性以外の項目をセットする場合はoptionAttributesで行ってください。 020 * 例えばアニメーションをOFFにする場合はanimation:falseをセットします。 021 * 022 * 出力されるスクリプトでは、idを指定しない場合はhybscanvas[tableId]が利用されます。 023 * 複数のグラフを同一画面で出力する場合はidかtableIdを変えてください。 024 * チャートオブジェクトはchart_[id]という名前で作成されるため、ajax等でコントロールが必要な場合は利用してください。 025 * 026 * @og.formSample 027 * ●形式:<og:column chartType="…" ... /> 028 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{$#064;XXXX} を解析します) 029 * 030 * ●Tag定義: 031 * <og:jsChart 032 * chartType ○【TAG】チャートの種類を指定します。(必須) 033 * id 【TAG】canvasタグのidを指定します。(初期値:hybscanvas) 034 * height 【TAG】チャートの高さを指定します。(初期値:400) 035 * width 【TAG】チャートの幅を指定します。(初期値:400) 036 * labelColumn 【TAG】ラベルのカラム名を指定します。(表示名称) 037 * title 【TAG】タイトルを指定します。 038 * titlePosition 【TAG】タイトルの表示位置[top/right/bottom/left]を指定します。(初期値:top) 039 * ylabel 【TAG】x軸のラベルを指定します。 040 * xlabel 【TAG】y軸のラベルを指定します。 041 * legendPosition 【TAG】凡例の表示位置[top/right/bottom/left]を指定します。(初期値:top) 042 * legendDisplay 【TAG】凡例を表示するか[true/false]を指定します。 043 * xscaleCallback 【TAG】x軸コールバックを指定します。 044 * yscaleCallback 【TAG】y軸コールバックを指定します。 045 * xscaleType 【TAG】x軸のスケールタイプ[category/time/linear]を指定します。(初期値:category) 046 * xmax 【TAG】x軸の最大値を指定します。(xscaleTypeがlinearの場合に有効) 047 * xmin 【TAG】x軸の最小値を指定します。(xscaleTypeがlinearの場合に有効) 048 * xstepSize 【TAG】x軸のメモリ幅を指定します。(xscaleTypeがlinearの場合に有効) 049 * timeUnit 【TAG】x軸のタイムの単位[year/quarter/month/week/day/hour/minute/second/millsecond]を指定します。(xscaleTypeがtimeの場合に有効。指定しない場合は自動) 050 * timeUnitStepSize 【TAG】x軸のタイムの単位幅を指定します。(xscaleTypeがtimeの場合に有効) 051 * timeSetFormat 【TAG】x軸の設定するタイムのフォーマットを指定します。(xscaleTypeがtimeの場合に有効) 052 * timeLblFormat 【TAG】x軸の表示するタイムのフォーマットを指定します。(xscaleTypeがtimeの場合に有効) 053 * timeMax 【TAG】x軸のタイムの最大値を指定します。(xscaleTypeがtimeの場合に有効) 054 * timeMin 【TAG】x軸のタイムの最小値を指定します。(xscaleTypeがtimeの場合に有効) 055 * yscaleType 【TAG】y軸のスケールタイプ[linear/category]を指定します。(初期値:linear) 056 * ycategoryList 【TAG】y軸のメモリリストをカンマ区切りで指定します。(xscaleTypeがlinearの場合に有効) 057 * max 【TAG】y軸の最大値を指定します。(xscaleTypeがlinearの場合に有効) 058 * min 【TAG】y軸の最小値を指定します。(xscaleTypeがlinearの場合に有効) 059 * stepSize 【TAG】y軸のメモリ幅を指定します。(xscaleTypeがlinearの場合に有効) 060 * barWidthPer 【TAG】棒線の横幅を指定します。(初期値:0.8, typeがbar,horizontalBarの場合に有効) 061 * onClick 【TAG】チャートクリック時のイベントを指定します。 062 * tableid 【TAG】(通常使いません)sessionから所得する DBTableModelオブジェクトの ID 063 * scope 【TAG】キャッシュする場合のスコープ[request/page/session/applicaton]を指定します(初期値:session) 064 * optionAttributes 【TAG】その他オプションを指定します。 065 * > ... Body ... 066 * </og:jsChart> 067 * ●使用例 068 * <og:jsChart 069 * chartType = "bar" 070 * labelColumn = "LDATA" 071 * id = "canvasid" 072 * height = "500" 073 * width = "800" 074 * labelColumn = "LCLM" 075 * title = "タイトル" 076 * titlePosition = "bottom" 077 * ylabel = "給料" 078 * xlabel = "名称" 079 * legendPosition = "right" 080 * legendDisplay = "true" 081 * xsclaeCallback = "function(value){return value + ' 様';}" 082 * ysclaeCallback = "function(value){return value.toLocaleString();}" 083 * xscaleType = "time" 084 * max = "1000000" 085 * min = "100000" 086 * stepSize = "10000" 087 * barWidthPer = "0.4" 088 * > 089 * <og:jsChartData ... /> 090 * </og:jsChart> 091 * 092 * @og.group 画面表示 093 * 094 * @version 5.9.17.2 2017/02/08 095 * @author T.OTA 096 * @since JDK7.0 097 * 098 */ 099public class JsChartTag extends CommonTagSupport { 100 //* このプログラムのVERSION文字列を設定します。{@value} */ 101 private static final String VERSION = "5.9.17.2 (2017/02/07)"; 102 private static final long serialVersionUID = 1631345224410617801L; 103 /** chartType 引数に渡す事の出来る アクション 折れ線 **/ 104 public static final String CTYPE_LINE = "line"; 105 /** chartType 引数に渡す事の出来る アクション 棒線 **/ 106 public static final String CTYPE_BAR = "bar"; 107 /** chartType 引数に渡す事の出来る アクション 横棒線 **/ 108 public static final String CTYPE_HBAR = "horizontalBar"; 109 /** chartType 引数に渡す事の出来る アクション レイダー **/ 110 public static final String CTYPE_RADAR = "radar"; 111 /** chartType 引数に渡す事の出来る アクション ポーラエリア **/ 112 public static final String CTYPE_PA = "polarArea"; 113 /** chartType 引数に渡す事の出来る アクション 円 **/ 114 public static final String CTYPE_PIE = "pie"; 115 /** chartType 引数に渡す事の出来る アクション ドーナツ **/ 116 public static final String CTYPE_DOUGHNUT = "doughnut"; 117 /** chartType 引数に渡す事の出来る アクション リスト */ 118 private static final String[] CTYPE_LIST = new String[] { CTYPE_LINE, CTYPE_BAR, CTYPE_HBAR, CTYPE_RADAR, CTYPE_PA, CTYPE_PIE, CTYPE_DOUGHNUT }; 119 /** chartType が円形のリスト */ 120 private static final String[] CTYPE_CI = new String[] { CTYPE_RADAR, CTYPE_PA, CTYPE_PIE, CTYPE_DOUGHNUT }; 121 private static final String[] TYPE_POSITION = new String[] { "top", "right", "bottom", "left" }; 122 private static final String[] TYPE_TIMEUNIT = new String[] { "year", "quarter", "month", "week", "day", "hour", "minute", "second", "millsecond" }; 123 private static final String[] TYPE_XSCALE = new String[] { "category", "time", "linear" }; 124 private static final String[] TYPE_YSCALE = new String[] { "linear", "category" }; 125 private static final String[] TYPE_BOOLEAN = new String[] { "true", "false" }; 126 127 private static final String CANVAS_NAME = "hybscanvas"; 128 129 // 変数宣言 130 private String id = null; // canvasタグのid 131 private String height = "400"; // canvasタグのheight 132 private String width = "400"; // canvasタグのwidth 133 private String chartType = null; // チャートタイプ 134 private String labelColumn = null; // ラベルカラム 135 private String ylabel = null; // y軸ラベル 136 private String xlabel = null; // x軸ラベル 137 private String scope = "session"; // スコープ 138 private String tableId = HybsSystem.TBL_MDL_KEY; // テーブルid 139 private List<JsChartData> jsChartData = null; // jsChartDataのリスト 140 private transient DBTableModel table = null; // DBTableModelクラス 141 private String optionAttributes = null; // オプション 142 private String onClick = null; // クリックイベント 143 private String title = null; // タイトル 144 private String titlePosition = null; // タイトル位置 145 private String legendPosition = null; // 凡例位置 146 private String legendDisplay = null; // 凡例表示フラグ 147 private String barWidthPer = null; // 棒線の横幅(パーセント) 148 private String xscaleCallback = null; // x軸のメモリ編集用コールバック 149 private String yscaleCallback = null; // y軸のメモリ編集用コールバック 150 private String xscaleType = null; // x軸のスケールタイプ 151 private String xmax = null; // x軸の最大値(リニアスケール用) 152 private String xmin = null; // x軸の最小値(リニアスケール用) 153 private String xstepSize = null; // x軸のメモリ幅(リニアスケール用) 154 private String yscaleType = null; // y軸のスケールタイプ 155 private String ycategoryList = null; // y軸のカテゴリーリスト(カテゴリースケール用) 156 private String max = null; // y軸の最大値(リニアスケール用) 157 private String min = null; // y軸の最小値(リニアスケール用) 158 private String stepSize = null; // y軸のメモリ幅(リニアスケール用) 159 private String timeUnit = null; // 時間の単位(タイムスケール用) 160 private String timeUnitStepSize = null; // 時間のメモリ幅(タイムスケール用) 161 private String timeSetFormat = null; // 時間の入力フォーマット(タイムスケール用) 162 private String timeLblFormat = null; // 時間の表示フォーマット(タイムスケール用) 163 private String timeMax = null; // 最大の時間(タイムスケール用) 164 private String timeMin = null; // 最小の時間(タイムスケール用) 165 166 /** 167 * タグリブオブジェクトをリリースします。 168 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 169 * 170 */ 171 @Override 172 protected void release2() { 173 super.release2(); 174 id = null; 175 height = "400"; 176 width = "400"; 177 chartType = null; 178 labelColumn = null; 179 scope = "session"; 180 tableId = HybsSystem.TBL_MDL_KEY; 181 jsChartData = null; 182 table = null; 183 optionAttributes = null; 184 onClick = null; 185 title = null; 186 titlePosition = null; 187 xlabel = null; 188 ylabel = null; 189 legendPosition = null; 190 legendDisplay = null; 191 barWidthPer = null; 192 xscaleCallback = null; 193 yscaleCallback = null; 194 xscaleType = null; 195 yscaleType = null; 196 ycategoryList = null; 197 max = null; 198 min = null; 199 stepSize = null; 200 timeUnit = null; 201 timeUnitStepSize = null; 202 timeSetFormat = null; 203 timeLblFormat = null; 204 timeMax = null; 205 timeMin = null; 206 xmax = null; 207 xmin = null; 208 xstepSize = null; 209 } 210 211 /** 212 * Taglibの開始タグが見つかった時に処理する doStartTag() を オーバーライドします。 213 * 214 * @return 後続処理の指示 215 */ 216 @Override 217 public int doStartTag() { 218 // チェック処理の実行 219 checkData(); 220 221 // スコープの設定 222 super.setScope( scope ); 223 224 // テーブル情報の取得 225 table = (DBTableModel) getObject( tableId ); 226 227 return EVAL_BODY_BUFFERED; // Bodyを評価する 228 } 229 230 /** 231 * チェック処理 232 */ 233 private void checkData() { 234 // xscaleTypeに「linear」、yscaleTypeに「category」を指定した場合は、エラー 235 if( "linear".equals( xscaleType ) && "category".equals( yscaleType ) ) { 236 StringBuilder errMsg = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 237 errMsg.append( "指定のスケールタイプの組み合わせは実行できません。" ); 238 errMsg.append( HybsSystem.CR ); 239 errMsg.append( "xscaleType:" ).append( xscaleType ).append( " yscaleType:" ).append( yscaleType ); 240 throw new HybsSystemException( errMsg.toString() ); 241 } 242 } 243 244 /** 245 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 246 * 247 * @return 後続処理の指示 248 */ 249 @Override 250 public int doEndTag() { 251 debugPrint(); 252 253 id = (id==null ? CANVAS_NAME + tableId : id ); // id指定なしの場合はCANVAS_NAME+tableId 254 255 // jsChart出力 256 jspPrint( jsChartOutput() ); 257 258 return EVAL_PAGE; 259 } 260 261 /** 262 * jsChart出力用 263 * jsChartTag と jsChartData を使用して、jsChart情報を出力します。 264 * 265 * @return jsChert用文字列 266 */ 267 private String jsChartOutput() { 268 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 269 270 // 各JavaScriptの変数名 271 String qd = "qd_" + id; //queryData 272 String cd = "cd_" + id; //chartData 273 String myChart = "chart_"+id; 274 String lblClm = labelColumn + id; 275 276 277 // JSON形式でテーブル情報を取得 278 ViewForm form = ViewFormFactory.newInstance( "JSON" ); 279 form.init( table ); 280 281 // canvasタグの設定 282 rtn.append( "<canvas class=\"").append( CANVAS_NAME).append( "\" id=\"" ).append( id ).append( "\" width=\"" ).append( width ).append( "\" height=\"" ).append( height ).append( "\"><!-- --></canvas>" ); 283 284 rtn.append( "<script>" ); 285 // query情報の取得(JSON) 286 rtn.append( "var ").append( qd ).append(" = " ).append( form.create() ); 287 288 // jsChartDataタグの変数宣言 289 for( int i = 0; i < jsChartData.size(); i++ ) { 290 rtn.append( " var " ).append( jsChartData.get( i ).getChartColumn() ).append( " = [];" ); 291 } 292 rtn.append( "var " ).append( lblClm ).append( " = [];" ); 293 294 // query情報をjsChartDataの変数に入れ替え 295 rtn.append( "for(var i=0; i < ").append( qd ).append( ".DATA.length; i++){" ); 296 for( int i = 0; i < jsChartData.size(); i++ ) { 297 String chartColumn = jsChartData.get( i ).getChartColumn(); 298 299 // x軸がlinearスケールの場合 300 if( "linear".equals( xscaleType ) ) { 301 // {x:ラベル, y:値}の形式で値を設定 302 rtn.append( chartColumn ).append( "[i] = {x:").append(qd).append(".DATA[i]." ).append( labelColumn ).append( ",y:").append(qd).append(".DATA[i]." ).append( chartColumn ).append( "};" ); 303 } 304 else { 305 // その他は値を設定 306 rtn.append( chartColumn ).append( "[i] = ").append(qd).append( ".DATA[i]." ).append( chartColumn ).append( ";" ); 307 } 308 } 309 rtn.append( lblClm ).append( "[i] = ").append( qd ).append( ".DATA[i]." ).append( labelColumn ).append( ";" ); 310 rtn.append( "}" ); 311 312 // y軸にカテゴリースケールを設定した場合 313 if( "category".equals( yscaleType ) ) { 314 rtn.append( "var ycateList = [];" ); 315 if( ycategoryList != null && ycategoryList.length() > 0 ) { 316 // 「,」を「','」に変換して設定。(,前後の半角スペースは除去する) 317 String regex = " *, *"; 318 Pattern p = Pattern.compile( regex ); 319 320 Matcher m = p.matcher( ycategoryList ); 321 // y軸カテゴリーリストの設定 322 rtn.append( "ycateList = ['" ).append( m.replaceAll( "','" ) ).append( "'];" ); 323 } 324 } 325 326 // jsChartDataの設定 327 rtn.append( "var ").append( cd ).append(" = {" ); 328 rtn.append( "labels:" ).append( lblClm ); 329 // y軸にカテゴリースケールを設定した場合 330 if( "category".equals( yscaleType ) ) { 331 rtn.append( ",yLabels:ycateList" ); 332 } 333 rtn.append( ",datasets:[" ); 334 for( int i = 0; i < jsChartData.size(); i++ ) { 335 if( i != 0 ) { 336 rtn.append( "," ); 337 } 338 rtn.append( jsChartData.get( i ).getParameter() ); 339 } 340 rtn.append( "]};" ); 341 342 // jsChartの生成 343 rtn.append( "var ").append( myChart ).append(" = new Chart(" ).append( id ).append( ",{" ); 344 rtn.append( "type:'" ).append( chartType ).append( "'" ); 345 rtn.append( ",data:").append(cd); 346 rtn.append( ",options:{" ); 347 rtn.append( "responsive:false" ); // レスポンシブ OFF 348// rtn.append( ",animation:false" ); // アニメーション OFF 349 350 // クリックイベントの設定 351 if( onClick != null && onClick.length() > 0 ) { 352 rtn.append( ",onClick:function(event,obj){" ).append( onClick ).append( "}" ); 353 } 354 355 // タイトル属性の設定 356 if( title != null && title.length() > 0 ) { 357 rtn.append( ",title:{" ); 358 rtn.append( "display:true" ); 359 setProp( rtn, ",text:'", title, "'" ); 360 setProp( rtn, ",position:'", titlePosition, "'" ); 361 rtn.append( "}" ); 362 } 363 364 // メモリ属性の設定 365 rtn.append( ",legend:{" ); 366 setProp( rtn, "display:", legendDisplay, "," ); 367 setProp( rtn, "position:'", legendPosition, "'" ); 368 rtn.append( "}" ); 369 370 // chartTypeの円形チェック 371 List<String> list = Arrays.asList( CTYPE_CI ); 372 if( list.contains( chartType ) ) { 373 // 円形の場合はscale属性に値を設定 374 rtn.append( ",scale: {ticks:{beginAtZero:true" ); 375 setProp( rtn, ",max:", max ); 376 setProp( rtn, ",min:", min ); 377 setProp( rtn, ",stepSize:", stepSize ); 378 rtn.append( "}}" ); 379 } 380 else { 381 // 円形以外の場合はscales属性に設定 382 rtn.append( ",scales:{" ); 383 if( CTYPE_HBAR.equals( chartType ) ) { 384 // 横棒線の場合はx軸の設定 385 rtn.append( "xAxes" ); 386 } 387 else { 388 // それ以外はy軸の設定 389 rtn.append( "yAxes" ); 390 } 391 rtn.append( ":[{" ); 392 setProp( rtn, "type:'", yscaleType, "'," ); 393 // y軸にカテゴリースケールを設定した場合 394 if( "category".equals( yscaleType )) { 395 rtn.append( "position:'left'," ); 396 } 397 if(ylabel != null && ylabel.length() > 0 ){ 398 rtn.append( "scaleLabel: {" ); 399 rtn.append( "display: true," ); 400 rtn.append( "labelString: '").append( ylabel ).append("'"); 401 rtn.append( "}," ); 402 } 403 rtn.append( "ticks:{beginAtZero:true" ); 404 setProp( rtn, ",max:", max ); 405 setProp( rtn, ",min:", min ); 406 setProp( rtn, ",stepSize:", stepSize ); 407 setProp( rtn, ",callback:", yscaleCallback ); 408 rtn.append( "}}]," ); 409 410 if( CTYPE_HBAR.equals( chartType ) ) { 411 // 横棒線の場合はy軸の設定 412 rtn.append( "yAxes" ); 413 } 414 else { 415 // それ以外はx軸の設定 416 rtn.append( "xAxes" ); 417 } 418 rtn.append( ":[{" ); 419 setProp( rtn, "type:'", xscaleType, "'," ); 420 setProp( rtn, "categoryPercentage:", barWidthPer, "," ); 421 // x軸にリニアスケールを設定した場合 422 if( "linear".equals( xscaleType ) ) { 423 rtn.append( "position:'bottom'," ); 424 } 425 // チャートタイプが横棒線の場合 426 if( CTYPE_HBAR.equals( chartType )){ 427 rtn.append( "position:'left'," ); 428 } 429 430 if(xlabel != null && xlabel.length() > 0 ){ 431 rtn.append( "scaleLabel: {" ); 432 rtn.append( "display: true," ); 433 rtn.append( "labelString: '").append( xlabel ).append("'"); 434 rtn.append( "}," ); 435 } 436 rtn.append( "time:{" ); 437 setProp( rtn, "format:'", timeSetFormat, "'," ); 438 // timeLblFormatが指定されている場合、全てのdisplayFormatsにtimeLblFormatを設定する 439 if( timeLblFormat != null && timeLblFormat.length() > 0 ) { 440 rtn.append( "displayFormats:{year:'" ).append( timeLblFormat ).append( "',quarter:'" ).append( timeLblFormat ).append( "',month:'" ).append( timeLblFormat ).append( "',week:'" ).append( timeLblFormat ).append( "',day:'" ).append( timeLblFormat ).append( "',hour:'" ).append( "',minute:'" ).append( timeLblFormat ).append( "',second:'" ).append( timeLblFormat ).append( "',millisecond:'" ).append( "'}," ); 441 } 442 setProp( rtn, "max:'", timeMax, "'," ); 443 setProp( rtn, "min:'", timeMin, "'," ); 444 setProp( rtn, "unit:'", timeUnit, "'," ); 445 setProp( rtn, "unitStepSize:", timeUnitStepSize ); 446 rtn.append( "}," ); 447 448 rtn.append( "ticks:{" ); 449 setProp( rtn, "callback:", xscaleCallback, "," ); 450 // x軸にリニアスケールを設定した場合 451 if( "linear".equals( xscaleType ) ) { 452 rtn.append( "beginAtZero:true," ); 453 setProp( rtn, "max:", xmax, "," ); 454 setProp( rtn, "min:", xmin, "," ); 455 setProp( rtn, "stepSize:", xstepSize ); 456 } 457 rtn.append( "}}]" ); 458 459 rtn.append( "}" ); 460 } 461 setProp( rtn, ",", optionAttributes ); 462 463 rtn.append( "}});" ); 464 rtn.append( "</script>" ); 465 466 return rtn.toString(); 467 } 468 469 /** 470 * setに値が存在する場合, 471 * sbにstr + setの形で値を追加する。 472 * 473 * @param sb 474 * @param str 475 * @param set 476 */ 477 private void setProp( StringBuilder sb, String str, String set ) { 478 if( set != null && set.length() > 0 ) { 479 sb.append( str ).append( set ); 480 } 481 } 482 483 /** 484 * setに値が存在する場合, 485 * sbにstr + set + endの形で値を追加する。 486 * 487 * @param sb 488 * @param str 489 * @param set 490 * @param end 491 */ 492 private void setProp( StringBuilder sb, String str, String set, String end ) { 493 if( set != null && set.length() > 0 ) { 494 sb.append( str ).append( set ).append( end ); 495 } 496 } 497 498 /** 499 * id を設定します。 500 * canvasタグのidに設定します。 501 * 502 * @param id 503 */ 504 public void setId( String id ) { 505 String temp = getRequestParameter( id ); 506 if( temp != null && temp.length() > 0 ) { 507 this.id = temp; 508 } 509 } 510 511 /** 512 * 高さ を設定します。 513 * canvasタグの高さに設定します。 514 * 515 * @param hei 516 */ 517 public void setHeight( final String hei ) { 518 String temp = getRequestParameter( hei ); 519 if( temp != null && temp.length() > 0 ) { 520 height = temp; 521 } 522 } 523 524 /** 525 * 横幅 を設定します。 526 * canvasタグの横幅を設定します。 527 * 528 * @param wid 529 */ 530 public void setWidth( final String wid ) { 531 String temp = getRequestParameter( wid ); 532 if( wid != null && wid.length() > 0 ) { 533 width = temp; 534 } 535 } 536 537 /** 538 * チャートタイプ を設定します。 539 * 540 * @param cType 541 */ 542 public void setChartType( final String cType ) { 543 chartType = getRequestParameter( cType ); 544 545 if( chartType != null && !check( chartType, CTYPE_LIST ) ) { 546 StringBuilder errMsg = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 547 errMsg.append( "指定のチャートタイプは実行できません。" ); 548 errMsg.append( HybsSystem.CR ); 549 errMsg.append( "chartType=[" ).append( chartType ).append( "]" ); 550 errMsg.append( HybsSystem.CR ); 551 for( int i = 0; i < CTYPE_LIST.length; i++ ) { 552 errMsg.append( " | " ); 553 errMsg.append( CTYPE_LIST[i] ); 554 } 555 throw new HybsSystemException( errMsg.toString() ); 556 } 557 } 558 559 /** 560 * ラベルカラムを指定します。 561 * 562 * @param labelColumn ラベルカラム 563 */ 564 public void setLabelColumn( String labelColumn ) { 565 this.labelColumn = getRequestParameter( labelColumn ); 566 } 567 568 /** 569 * テーブルスコープを指定します。 570 * 571 * @param scope テーブルスコープ 572 */ 573 public void setScope( String scope ) { 574 this.scope = getRequestParameter( scope ); 575 } 576 577 /** 578 * テーブルIDを指定します。 579 * 580 * @param tableId テーブルID 581 */ 582 public void setTableId( String tableId ) { 583 this.tableId = getRequestParameter( tableId ); 584 } 585 586 /** 587 * オプション情報を指定します。 588 * 589 * @param optionAttributes オプションの値 590 */ 591 public void setOptionAttributes( String optionAttributes ) { 592 this.optionAttributes = getRequestParameter( optionAttributes ); 593 } 594 595 /** 596 * チャートクリック時のイベントを指定します。 597 * 下記の値が引数として渡されます。 598 * 599 * event:イベント情報 600 * obj:クリックされたオブジェクトの情報 601 * 602 * @param onClick 603 */ 604 public void setOnClick( String onClick ) { 605 this.onClick = getRequestParameter( onClick ); 606 } 607 608 /** 609 * メモリの最大値を指定します。 610 * 611 * @param max メモリの最大値 612 */ 613 public void setMax( String max ) { 614 this.max = getRequestParameter( max ); 615 } 616 617 /** 618 * メモリの最小値を指定します。 619 * 620 * @param min メモリの最小値 621 */ 622 public void setMin( String min ) { 623 this.min = getRequestParameter( min ); 624 } 625 626 /** 627 * メモリ幅を設定します。 628 * 629 * @param stepSize 630 */ 631 public void setStepSize( String stepSize ) { 632 this.stepSize = getRequestParameter( stepSize ); 633 } 634 635 /** 636 * 時間の単位を設定します。 637 * 638 * @param timeUnit 639 */ 640 public void setTimeUnit( String timeUnit ) { 641 this.timeUnit = getRequestParameter( timeUnit ); 642 643 checkPara( this.timeUnit, TYPE_TIMEUNIT, "timeUnit" ); 644 } 645 646 /** 647 * 時間のメモリ幅を設定します。 648 * 649 * @param timeUnitStepSize 650 */ 651 public void setTimeUnitStepSize( String timeUnitStepSize ) { 652 this.timeUnitStepSize = getRequestParameter( timeUnitStepSize ); 653 } 654 655 /** 656 * 時間の入力フォーマットを設定します。 657 * 658 * @param timeSetFormat 659 */ 660 public void setTimeSetFormat( String timeSetFormat ) { 661 this.timeSetFormat = getRequestParameter( timeSetFormat ); 662 } 663 664 /** 665 * 時間の表示フォーマットを設定します。 666 * 667 * @param timeLblFormat 668 */ 669 public void setTimeLblFormat( String timeLblFormat ) { 670 this.timeLblFormat = getRequestParameter( timeLblFormat ); 671 } 672 673 /** 674 * 時間の最大値を設定します。 675 * 676 * @param timeMax 677 */ 678 public void setTimeMax( String timeMax ) { 679 this.timeMax = getRequestParameter( timeMax ); 680 } 681 682 /** 683 * 時間の最小値を設定します。 684 * 685 * @param timeMin 686 */ 687 public void setTimeMin( String timeMin ) { 688 this.timeMin = getRequestParameter( timeMin ); 689 } 690 691 /** 692 * タイトルを設定します。 693 * 694 * @param title 695 */ 696 public void setTitle( String title ) { 697 this.title = getRequestParameter( title ); 698 } 699 700 /** 701 * タイトル位置を設定します。 702 * 703 * @param titlePosition 704 */ 705 public void setTitlePosition( String titlePosition ) { 706 this.titlePosition = getRequestParameter( titlePosition ); 707 708 checkPara( this.titlePosition, TYPE_POSITION, "titlePosition" ); 709 } 710 711 /** 712 * 凡例位置を設定します。 713 * 714 * @param legendPosition 715 */ 716 public void setLegendPosition( String legendPosition ) { 717 this.legendPosition = getRequestParameter( legendPosition ); 718 719 checkPara( this.legendPosition, TYPE_POSITION, "legendPosition" ); 720 } 721 722 /** 723 * 凡例の表示制御を設定します。 724 * 725 * @param legendDisplay 726 */ 727 public void setLegendDisplay( String legendDisplay ) { 728 this.legendDisplay = getRequestParameter( legendDisplay ); 729 730 checkPara( this.legendDisplay, TYPE_BOOLEAN, "legendDisplay" ); 731 } 732 733 /** 734 * x軸のメモリ編集用スケールバックを設定します。 735 * 736 * @param xscaleCallback 737 */ 738 public void setXscaleCallback( String xscaleCallback ) { 739 this.xscaleCallback = getRequestParameter( xscaleCallback ); 740 } 741 742 /** 743 * y軸のメモリ編集用スケールバックを設定します。 744 * 745 * @param yscaleCallback 746 */ 747 public void setYscaleCallback( String yscaleCallback ) { 748 this.yscaleCallback = getRequestParameter( yscaleCallback ); 749 } 750 751 /** 752 * x軸のスケールタイプを設定します。 753 * 754 * @param xscaleType 755 */ 756 public void setXscaleType( String xscaleType ) { 757 this.xscaleType = getRequestParameter( xscaleType ); 758 759 checkPara( this.xscaleType, TYPE_XSCALE, "xscaleType" ); 760 } 761 762 /** 763 * y軸のスケールタイプを設定します。 764 * 765 * @param yscaleType 766 */ 767 public void setYscaleType( String yscaleType ) { 768 this.yscaleType = getRequestParameter( yscaleType ); 769 770 checkPara( this.yscaleType, TYPE_YSCALE, "yscaleType" ); 771 } 772 773 /** 774 * y軸のカテゴリー一覧を設定します。 775 * 776 * @param ycategoryList 777 */ 778 public void setYcategoryList( String ycategoryList ) { 779 this.ycategoryList = getRequestParameter( ycategoryList ); 780 } 781 782 /** 783 * x軸の最大値を設定します。 784 * 785 * @param xmax 786 */ 787 public void setXmax( String xmax ) { 788 this.xmax = getRequestParameter( xmax ); 789 } 790 791 /** 792 * x軸の最小値を設定します。 793 * 794 * @param xmin 795 */ 796 public void setXmin( String xmin ) { 797 this.xmin = getRequestParameter( xmin ); 798 } 799 800 /** 801 * x軸のメモリ幅を設定します。 802 * 803 * @param xstepSize 804 */ 805 public void setXstepSize( String xstepSize ) { 806 this.xstepSize = getRequestParameter( xstepSize ); 807 } 808 809 /** 810 * 棒線の横幅を設定します。 811 * 812 * @param barWidthPer 813 */ 814 public void setBarWidthPer( String barWidthPer ) { 815 this.barWidthPer = getRequestParameter( barWidthPer ); 816 } 817 818 /** 819 * y軸のラベルを設定します。 820 * 821 * @param ylabel 822 */ 823 public void setYlabel( String ylabel ) { 824 this.ylabel = getRequestParameter( ylabel ); 825 } 826 827 /** 828 * x軸のラベルを設定します。 829 * 830 * @param xlabel 831 */ 832 public void setXlabel( String xlabel ) { 833 this.xlabel = getRequestParameter( xlabel ); 834 } 835 836 /** 837 * jsChartData情報をリストに追加します。 838 * リストが存在しない場合は、新しく作成します。 839 * 840 * @param jsData 841 */ 842 public void addJsChartData( final JsChartData jsData ) { 843 if( jsChartData == null ) { 844 jsChartData = new ArrayList<JsChartData>(); 845 } 846 jsChartData.add( jsData ); 847 } 848 849 /** 850 * パラメータチェック用メソッド 851 * 852 * @param trg 853 * @param list 854 * @param trgStr 855 */ 856 private void checkPara( String trg, String[] list, String trgStr ) { 857 if( trg != null && trg.length() > 0 && !check( trg, list ) ) { 858 StringBuilder errMsg = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 859 errMsg.append( "指定の" ).append( trgStr ).append( "は指定できません。" ); 860 errMsg.append( HybsSystem.CR ); 861 errMsg.append( trgStr ).append( "=[" ).append( trg ).append( "]" ); 862 errMsg.append( HybsSystem.CR ); 863 for( int i = 0; i < list.length; i++ ) { 864 errMsg.append( " | " ); 865 errMsg.append( list[i] ); 866 } 867 throw new HybsSystemException( errMsg.toString() ); 868 } 869 } 870 871 /** 872 * このオブジェクトの文字列表現を返します。 873 * 基本的にデバッグ目的に使用します。 874 * 875 * @return このクラスの文字列表現 876 */ 877 public String toString() { 878 // JSON形式でテーブル情報を取得 879 ViewForm form = ViewFormFactory.newInstance( "JSON" ); 880 form.init( table ); 881 882 // jsChartDataのパラメータ情報 883 StringBuilder sb = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 884 for( int i = 0; i < jsChartData.size(); i++ ) { 885 sb.append( " jsChartData" ).append( i ).append( ":" ).append( jsChartData.get( i ).getParameter() ); 886 } 887 888 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 889 .println( "VERSION", VERSION ) 890 .println( "id", id ) 891 .println( "tableId", tableId ) 892 .println( "scope", scope ) 893 .println( "chartType", chartType ) 894 .println( "width", width ) 895 .println( "height", height ) 896 .println( "max", max ) 897 .println( "min", min ) 898 .println( "stepSize", stepSize ) 899 .println( "barWidthPer", barWidthPer ) 900 .println( "timeUnit", timeUnit ) 901 .println( "timeUnitStepSize", timeUnitStepSize ) 902 .println( "timeLblFormat", timeLblFormat ) 903 .println( "timeSetFormat", timeSetFormat ) 904 .println( "timeMax", timeMax ) 905 .println( "timeMin", timeMin ) 906 .println( "title", title ) 907 .println( "titlePosition", titlePosition ) 908 .println( "xlabel", xlabel ) 909 .println( "ylabel", ylabel ) 910 .println( "legendPosition", legendPosition ) 911 .println( "legendDisplay", legendDisplay ) 912 .println( "yscaleCallback", yscaleCallback ) 913 .println( "xscaleCallback", xscaleCallback ) 914 .println( "xscaleType", xscaleType ) 915 .println( "xmax", xmax ) 916 .println( "xmin", xmin ) 917 .println( "xstepSize", xstepSize ) 918 .println( "yscaleType", yscaleType ) 919 .println( "ycategoryList", ycategoryList ) 920 .println( "optionAttributes", optionAttributes ) 921 .println( "JSON", form.create() ) 922 .println( "jsChartDataPara", sb.toString() ).fixForm().toString(); 923 } 924}