portal-chart.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. if($ == undefined){
  2. $ = jQuery;
  3. }
  4. /**
  5. * 插入图形前先调用 图形类型选择框
  6. * @param layoutId
  7. * @param charttype
  8. * @return
  9. */
  10. function insertChart(layoutId, charttype, typeIndex, maparea){
  11. var tp = charttype ? charttype : "line";
  12. curTmpInfo.charttype = tp; //放入全局对象,后面crtChart方法访问
  13. var compId = newGuid();
  14. var name = "图表";
  15. var comp = {"id":compId, "name":name, "type":"chart"};
  16. comp.chartJson = {"type":tp, maparea:maparea, typeIndex:typeIndex, xcol:{}, ycol:{}, scol:{}, params:[],height:tp == 'map' ? '400':'250'};
  17. if(curTmpInfo.is3g == "y"){
  18. //3G 报表图形宽度为100%
  19. comp.chartJson.width = "100%";
  20. }else{
  21. comp.chartJson.width = tp=='pie'||tp=='gauge'?'360':'600';
  22. }
  23. comp.kpiJson = [null, null, null];
  24. var str = addComp(comp, layoutId, true);
  25. $("#layout_"+layoutId).append(str);
  26. //注册拖放事件
  27. bindCompEvent(comp);
  28. bindResizeEvent(comp.id, 'chart');
  29. //滚动位置
  30. window.setTimeout(function(){
  31. $("#optarea").scrollTop($("#c_"+compId).offset().top);
  32. }, 500);
  33. }
  34. function editChartData(compId, layoutId){
  35. if($("#dataProperty").size() == 0){
  36. $('#Jlayout').layout('add', {region:"south", id:"dataProperty", split:false, collapsible:false,height : 120, title:'编辑图形数据', tools:[{
  37. iconCls:'icon-cancel',
  38. handler:function(){
  39. $('#Jlayout').layout("remove", "south");
  40. }
  41. }]});
  42. }else{
  43. $('#Jlayout').layout('panel', "south").panel("setTitle", "编辑图形数据");
  44. }
  45. //切换数据到立方体
  46. $("#comp_tab").tabs("select", 1);
  47. var comp = findCompById(compId);
  48. var charttype = comp.chartJson.type;
  49. var ispie = false;
  50. var isscatter = false;
  51. var isbubble = false;
  52. var ismap = false;
  53. ispie = charttype == 'pie' || charttype == 'gauge';
  54. isscatter = charttype == 'bubble' || charttype == 'scatter';
  55. isbubble = charttype == 'bubble';
  56. ismap = charttype == "map";
  57. isnesting = charttype == 'pie' && comp.chartJson && comp.chartJson.typeIndex== "3";
  58. var y2str = ""; //第二纵轴
  59. if(comp.kpiJson[1] != null){
  60. y2str = "<span title=\""+comp.kpiJson[1].kpi_name+"\" class=\"charttxt\">"+(comp.kpiJson[1].kpi_name)+"</span><span onclick=\"chartmenu(this, "+comp.kpiJson[1].kpi_id+",'y2col','"+comp.kpiJson[1].kpi_name+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>";
  61. }else{
  62. y2str = "<span class=\"charttip\">将度量拖到这里</span>";
  63. }
  64. var str = "<div class=\"tsbd\">" + (isscatter?"<div class=\"ts_h\">" + (ispie ? "观察维度" : "横轴")+":<div id=\"y2col\" class=\"h_ctx\">"+(comp.kpiJson[1]!=null?"<span title=\""+comp.kpiJson[1].kpi_name+"\" class=\"charttxt\">"+(comp.kpiJson[1].kpi_name)+"</span><span onclick=\"chartmenu(this, "+comp.kpiJson[1].kpi_id+",'y2col','"+comp.kpiJson[1].kpi_name+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">将度量拖到这里</span>")+"</div></div>":"<div class=\"ts_h\">" + (ispie ? "观察维度" : (ismap?"地域维度":"横轴"))+":<div id=\"xcol\" class=\"h_ctx\">"+(comp.chartJson.xcol&&comp.chartJson.xcol.id?"<span class=\"charttxt\" title=\""+comp.chartJson.xcol.dimdesc+"\">"+comp.chartJson.xcol.dimdesc+"</span><span onclick=\"chartmenu(this, "+comp.chartJson.xcol.id+",'xcol', '"+comp.chartJson.xcol.dimdesc+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">"+(ismap?"将地域拖到这里":"将维度拖到这里")+"</span>")+"</div></div>") + (isnesting?"<div class=\"ts_h\">外环维度:<div id=\"scol\" class=\"h_ctx\">"+(comp.chartJson.scol&&comp.chartJson.scol.id?"<span class=\"charttxt\" title=\""+comp.chartJson.scol.dimdesc+"\">"+comp.chartJson.scol.dimdesc+"</span><span onclick=\"chartmenu(this,"+comp.chartJson.scol.id+", 'scol', '"+comp.chartJson.scol.dimdesc+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">将维度拖到这里</span>")+"</div></div>":"") +
  65. "<div class=\"ts_h\">"+(ispie||ismap?"度量":"纵轴")+":<div id=\"ycol\" class=\"h_ctx\">"+(comp.kpiJson[0]!=null?"<span class=\"charttxt\" title=\""+comp.kpiJson[0].kpi_name+"\">"+(comp.kpiJson[0].kpi_name)+"</span><span onclick=\"chartmenu(this, "+comp.kpiJson[0].kpi_id+",'ycol','"+comp.kpiJson[0].kpi_name+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">将度量拖到这里</span>")+"</div></div>" +
  66. (isbubble ? "<div class=\"ts_h\">气泡大小:<div id=\"y3col\" class=\"h_ctx\">"+(comp.kpiJson[2]!=null?"<span title=\""+comp.kpiJson[2].kpi_name+"\" class=\"charttxt\">"+(comp.kpiJson[2].kpi_name)+"</span><span onclick=\"chartmenu(this, "+comp.kpiJson[2].kpi_id+",'y3col','"+comp.kpiJson[2].kpi_name+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">将度量拖到这里</span>")+"</div></div>":"") +
  67. (isscatter?"<div class=\"ts_h\">观察维度:<div id=\"xcol\" class=\"h_ctx\">"+(comp.chartJson.xcol&&comp.chartJson.xcol.id?"<span class=\"charttxt\" title=\""+comp.chartJson.xcol.dimdesc+"\">"+comp.chartJson.xcol.dimdesc+"</span><span onclick=\"chartmenu(this, "+comp.chartJson.xcol.id+",'xcol', '"+comp.chartJson.xcol.dimdesc+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">将维度拖到这里</span>")+"</div></div>":"") +
  68. (isbubble || ismap ? "":"<div class=\"ts_h\" "+(ispie?"style=\"display:none\"":"")+">图例:<div id=\"scol\" class=\"h_ctx\">"+(comp.chartJson.scol&&comp.chartJson.scol.id?"<span class=\"charttxt\" title=\""+comp.chartJson.scol.dimdesc+"\">"+comp.chartJson.scol.dimdesc+"</span><span onclick=\"chartmenu(this,"+comp.chartJson.scol.id+", 'scol', '"+comp.chartJson.scol.dimdesc+"','"+compId+"')\" title=\"配置\" class=\"charticon\"></span>":"<span class=\"charttip\">将维度拖到这里</span>")+"</div></div>") +
  69. /** 对于 (curTmpInfo.chart.chartJson.type=="column"&&curTmpInfo.chart.chartJson.typeIndex=="2" 表示双坐标轴,现在曲线图、柱状图都支持双坐标*/
  70. ((charttype=="column"||charttype=="line")&&(comp.chartJson.typeIndex=="2"||comp.chartJson.typeIndex=="4")?"<div class=\"ts_h\">第二纵轴:<div class=\"h_ctx\" id=\"y2col\">"+y2str+"</div></div>":"") + "</div>";
  71. var ctx = "<div style=\"margin:10px;\"><div class=\"chartDatasty\" id=\"chartData\">"+str+"</div></div>";
  72. $("#dataProperty").html(ctx);
  73. //注册度量及维度拖拽事件
  74. initChartKpiDrop(compId);
  75. }
  76. function initChartKpiDrop(id){
  77. $("#chartData #xcol, #chartData #ycol, #chartData #y2col, #chartData #y3col, #chartData #scol").droppable({
  78. accept:"#datasettree .tree-node",
  79. onDragEnter:function(e,source){
  80. var node = $("#datasettree").tree("getNode", source);
  81. var tp = node.attributes.col_type;
  82. var targetid = $(this).attr("id");
  83. if(tp == 1 && (targetid == 'xcol' || targetid == 'scol')){
  84. $(source).draggable('proxy').find("span").removeClass("tree-dnd-no");
  85. $(source).draggable('proxy').find("span").addClass("tree-dnd-yes");
  86. $("#chartData #"+targetid).css("border-color", "#ff0000");
  87. }
  88. if(tp == 2 && (targetid == "ycol" || targetid == "y2col" || targetid == "y3col")){
  89. $(source).draggable('proxy').find("span").removeClass("tree-dnd-no");
  90. $(source).draggable('proxy').find("span").addClass("tree-dnd-yes");
  91. $("#chartData #" + targetid).css("border-color", "#ff0000");
  92. }
  93. e.cancelBubble=true;
  94. e.stopPropagation(); //阻止事件冒泡
  95. },
  96. onDragLeave:function(e,source){
  97. $(source).draggable('proxy').find("span").addClass("tree-dnd-no");
  98. $(source).draggable('proxy').find("span").removeClass("tree-dnd-yes");
  99. $("#chartData #"+$(this).attr("id")).css("border-color", "#7F9DB9");
  100. e.cancelBubble=true;
  101. e.stopPropagation(); //阻止事件冒泡
  102. },
  103. onDrop:function(e,source){
  104. var json = findCompById(id);
  105. //清除边框样式
  106. $("#chartData #"+$(this).attr("id")).css("border-color", "#7F9DB9");
  107. //获取TREE
  108. var node = $("#datasettree").tree("getNode", source);
  109. e.cancelBubble=true;
  110. e.stopPropagation(); //阻止事件冒泡
  111. //判断拖入的维度及度量是否和以前维度及度量在同一个表。
  112. if(json.cubeId != undefined){
  113. if(json.cubeId != node.attributes.cubeId){
  114. msginfo("您拖入的"+ (node.attributes.col_type == 2 ? "度量" : "维度") +"与组件已有的内容不在同一个数据表中,拖放失败。");
  115. return;
  116. }
  117. }
  118. //如果是地图,横轴必须是省/地市等地域维度
  119. if(json.chartJson.type == "map" && node.attributes.col_type == 1 && $(this).attr("id") == "xcol"){
  120. if(!(node.attributes.dim_type == 'prov' || node.attributes.dim_type == 'city')){
  121. msginfo("只能拖放地域维度到横轴!");
  122. return;
  123. }
  124. var maparea = json.chartJson.maparea;
  125. if(maparea == "china"){
  126. if(node.attributes.dim_type == 'city'){
  127. msginfo("只能把省份维度拖放到全国地图上!");
  128. return;
  129. }
  130. }else{
  131. if(node.attributes.dim_type == 'prov'){
  132. msginfo("只能把地市维度拖放到 " + json.chartJson.mapAreaName+ " 地图上!");
  133. return;
  134. }
  135. }
  136. }
  137. json.cubeId = node.attributes.cubeId;
  138. json.dsetId = node.attributes.dsetId;
  139. json.dsid = node.attributes.dsid;
  140. var targetid = $(this).attr("id");
  141. var nestingPie = json.chartJson && json.chartJson.type == "pie" && json.chartJson.typeIndex== "3" //是否是嵌套圆环图
  142. if(node.attributes.col_type == 2 && (targetid == "ycol" || targetid == "y2col" || targetid == "y3col")){
  143. var ooo = {"kpi_id":node.attributes.col_id, "kpi_name" : node.text, ydispName:node.text, "col_name":node.attributes.col_name, "aggre":node.attributes.aggre, "fmt":node.attributes.fmt, "alias":node.attributes.alias,"unit":node.attributes.unit,"rate":node.attributes.rate,"tname":node.attributes.tname,"calc":node.attributes.calc};
  144. if(targetid == "ycol"){
  145. json.kpiJson[0] = ooo;
  146. }else if(targetid == "y2col"){
  147. json.kpiJson[1] = ooo;
  148. }else{
  149. json.kpiJson[2] = ooo;
  150. }
  151. json.chartJson.ycol = {"type":"kpi"};
  152. $(this).html("<span class=\"charttxt\" title=\""+node.text+"\">" + node.text + "</span><span class=\"charticon\" title=\"配置\" onclick=\"chartmenu(this, "+node.attributes.col_id+",'"+targetid+"','"+node.text+"','"+json.id+"')\"></span>");
  153. curTmpInfo.isupdate = true;
  154. chartview(json, id);
  155. }
  156. if(node.attributes.col_type == 1 && targetid == "xcol"){
  157. //判断是否在xcol中已经存在
  158. if(json.chartJson.scol != undefined && json.chartJson.scol.id == node.attributes.col_id){
  159. msginfo("您拖放的维度已存在于图例项中,不能拖放。")
  160. return;
  161. }
  162. //判断xcol 和 scol 是否属于一个分组,如果是,不让拖动
  163. var gt = node.attributes.grouptype;
  164. if(gt != null && gt != '' && !nestingPie){
  165. if(json.chartJson.scol != undefined && json.chartJson.scol.grouptype == gt){
  166. msginfo("您拖放的维度与此图形中已有维度分类相同,不能拖放。")
  167. return;
  168. }
  169. }
  170. json.chartJson.xcol = {"id":node.attributes.col_id, "dimdesc" : node.text,xdispName:node.text, "type":node.attributes.dim_type, "colname":node.attributes.col_name,"iscas":node.attributes.iscas, "tableName":node.attributes.tableName, "tableColKey":node.attributes.tableColKey,"tableColName":node.attributes.tableColName, "dimord":node.attributes.dimord, "dim_name":node.attributes.dim_name, "grouptype":node.attributes.grouptype,"valType":node.attributes.valType, "ordcol":node.attributes.ordcol,"alias":node.attributes.alias,"tname":node.attributes.tname,"calc":node.attributes.calc};
  171. $(this).html("<span class=\"charttxt\" title=\""+node.text+"\">" + node.text + "</span><span class=\"charticon\" title=\"配置\" onclick=\"chartmenu(this, "+node.attributes.col_id+",'xcol', '"+node.text+"','"+json.id+"')\"></span>");
  172. curTmpInfo.isupdate = true;
  173. chartview(json, id);
  174. }
  175. if(node.attributes.col_type == 1 && targetid == "scol"){
  176. //判断是否在xcol中已经存在
  177. if(json.chartJson.xcol != undefined && json.chartJson.xcol.id == node.attributes.col_id){
  178. msginfo("您拖放的维度已存在于横轴中,不能拖放。")
  179. return;
  180. }
  181. //判断xcol 和 scol 是否属于一个分组,如果是,不让拖动
  182. var gt = node.attributes.grouptype;
  183. if(gt != null && gt != '' && !nestingPie){
  184. if(json.chartJson.xcol != undefined && json.chartJson.xcol.grouptype == gt){
  185. msginfo("您拖放的维度与此图形中已有维度分类相同,不能拖放。")
  186. return;
  187. }
  188. }
  189. json.chartJson.scol = {"id":node.attributes.col_id, "dimdesc" : node.text, "type":node.attributes.dim_type, "colname":node.attributes.col_name,"iscas":node.attributes.iscas, "tableName":node.attributes.tableName, "tableColKey":node.attributes.tableColKey,"tableColName":node.attributes.tableColName, "dimord":node.attributes.dimord, "dim_name":node.attributes.dim_name, "grouptype":node.attributes.grouptype,"valType":node.attributes.valType, "ordcol":node.attributes.ordcol, "alias":node.attributes.alias,"tname":node.attributes.tname,"calc":node.attributes.calc};
  190. $(this).html("<span class=\"charttxt\" title=\""+node.text+"\">" + node.text + "</span><span class=\"charticon\" title=\"配置\" onclick=\"chartmenu(this,"+node.attributes.col_id+", 'scol', '"+node.text+"','"+json.id+"')\"></span>");
  191. curTmpInfo.isupdate = true;
  192. chartview(json, id);
  193. }
  194. }
  195. });
  196. }
  197. /**
  198. * 如果 addChart == true, 调用insertChart函数
  199. * @param addChart
  200. * @param layoutId
  201. * @param compId
  202. * @return
  203. */
  204. function setcharttype(addChart, layoutId){
  205. if(!layoutId){
  206. layoutId = curTmpInfo.layoutId;
  207. }
  208. var comp;
  209. var ctp;
  210. var cindex;
  211. var maparea;
  212. var mapAreaName;
  213. if(!addChart){
  214. comp = findCompById(curTmpInfo.compId);
  215. ctp = comp.chartJson.type;
  216. cindex = comp.chartJson.typeIndex;
  217. maparea = comp.chartJson.maparea;
  218. mapAreaName = comp.chartJson.mapAreaName;
  219. }
  220. if($("#cpdailog").size() == 0){
  221. $("<div id=\"cpdailog\"></div>").appendTo("body");
  222. }
  223. $('#cpdailog').dialog({
  224. title: "选择图表类型",
  225. width: 550,
  226. height: 410,
  227. closed: false,
  228. cache: false,
  229. modal: true,
  230. toolbar:null,
  231. href:'ChartType.action',
  232. onLoad:function(){
  233. //如果是 addChart 设置默认值
  234. var cid;
  235. if(addChart){
  236. cid = 1;
  237. cindex = "1";
  238. maparea = "china";
  239. mapAreaName = "全国";
  240. }else{ //回写值
  241. var cid = 1;
  242. if(ctp == 'line'){
  243. cid = 1;
  244. }else if(ctp == 'column'){
  245. cid = 2;
  246. }else if(ctp == 'pie'){
  247. cid = 3;
  248. }else if(ctp == 'radar'){
  249. cid = 5;
  250. }else if(ctp == 'gauge'){
  251. cid = 4;
  252. }else if(ctp == 'scatter'){
  253. cid = 6;
  254. }else if(ctp == 'bubble'){
  255. cid = 7;
  256. }else if(ctp == 'bar'){
  257. cid = 8;
  258. }else if(ctp == 'area'){
  259. cid = 9;
  260. }else if(ctp == "map"){
  261. cid = 10;
  262. }
  263. cindex = comp.chartJson.typeIndex;
  264. if(!cindex){
  265. cindex = "1";
  266. }
  267. }
  268. $(".chartselect .selleft ul li[cid='"+cid+"']").addClass("select");
  269. $(".chartselect .selright .one").css("display", "none");
  270. $("#cpdailog #schart" + cid).css("display", "block");
  271. //选中二级
  272. $("#cpdailog #schart"+cid+" span[index='"+cindex+"']").addClass("select");
  273. //选择图形类型事件
  274. $(".chartselect .selleft ul li").bind("click", function(){
  275. var cid = $(this).attr("cid");
  276. $(".chartselect .selleft ul li").removeClass("select");
  277. $(this).addClass("select");
  278. $(".chartselect .selright .one").css("display", "none");
  279. $("#cpdailog #schart" + cid).css("display", "block");
  280. //控制二级
  281. $(".chartselect .selright .one span.charttype").removeClass("select");
  282. $("#cpdailog #schart"+cid+" span[index='1']").addClass("select");
  283. var tp = $("#cpdailog #schart" + cid).attr("tp");
  284. ctp = tp;
  285. cindex = "1";
  286. });
  287. //右边选择
  288. $(".chartselect .selright .one span.charttype").bind("click", function(){
  289. $(".chartselect .selright .one span.charttype").removeClass("select");
  290. $(this).addClass("select");
  291. cindex = $(this).attr("index");
  292. });
  293. //地图地域选择
  294. $("#cpdailog #maparea").val(maparea+","+mapAreaName).bind("change", function(){
  295. var vls = $(this).val().split(",");
  296. maparea = vls[0];
  297. mapAreaName = vls[1];
  298. });
  299. },
  300. onClose:function(){
  301. $('#cpdailog').dialog('destroy');
  302. },
  303. buttons:[{
  304. text:'确定',
  305. iconCls:"icon-ok",
  306. handler:function(){
  307. $('#cpdailog').dialog('close');
  308. if(addChart){
  309. insertChart(layoutId, ctp, cindex, maparea, mapAreaName);
  310. }else{
  311. comp.chartJson.type = ctp;
  312. comp.chartJson.typeIndex = cindex;
  313. if(ctp == "bubble" || ctp == "pie" || ctp =="gauge" || (ctp=="line"&&cindex=="2") || (ctp=="column"&&cindex=="2")){
  314. comp.chartJson.scol = {}; //气泡图, 饼图、仪表盘清除scol, 多轴曲线图和柱状图,清除scol
  315. }
  316. if(ctp != "bubble" && ctp != "scatter"){ //除了散点图和气泡图,清除第二度量,第三度量
  317. comp.kpiJson[1] = null;
  318. comp.kpiJson[2] = null;
  319. }
  320. if(ctp == "map"){
  321. comp.chartJson.maparea = maparea;
  322. comp.chartJson.mapAreaName = mapAreaName;
  323. }else{
  324. delete comp.chartJson.maparea;
  325. delete comp.chartJson.mapAreaName;
  326. }
  327. $('#Jlayout').layout("remove", "east");
  328. $('#Jlayout').layout("remove", "south");
  329. chartview(comp, comp.id);
  330. }
  331. }
  332. },{
  333. text:'取消',
  334. iconCls:"icon-cancel",
  335. handler:function(){
  336. $('#cpdailog').dialog('close');
  337. }
  338. }
  339. ]});
  340. }
  341. function resetchart(compId){
  342. //重置图形区域为空
  343. $("#c_" + compId + " div.cctx div.ccctx").html("<div align=\"center\" class=\"tipinfo\">(点击组件右上角设置按钮配置图形数据)</div>");
  344. }
  345. function chartview(json, compId){
  346. if(json.kpiJson[0] == null){
  347. resetchart(compId);
  348. return;
  349. }
  350. if(json.chartJson.type == "scatter" && json.kpiJson[1] == null ){
  351. resetchart(compId);
  352. return;
  353. }
  354. if(json.chartJson.type == "bubble" && json.kpiJson[2] == null ){
  355. resetchart(compId);
  356. return;
  357. }
  358. __showLoading();
  359. var chartJson = JSON.parse(JSON.stringify(json));
  360. chartJson.portalParams = pageInfo.params;
  361. $.ajax({
  362. type: "POST",
  363. url: "ChartView.action",
  364. contentType : "application/json",
  365. dataType:"html",
  366. data: JSON.stringify(chartJson),
  367. success: function(resp){
  368. __hideLoading();
  369. $("#c_" + compId + " div.cctx div.ccctx").html(resp);
  370. },
  371. error:function(resp){
  372. __hideLoading();
  373. $.messager.alert('出错了','系统出错,请查看后台日志。','error');
  374. }
  375. });
  376. }
  377. function setChartProperty(comp){
  378. if($("#compSet").size() == 0){
  379. $('#Jlayout').layout('add', {region:"east", split:false, width:240, title:"图形属性设置", collapsible:false, id:"compSet", tools:[{
  380. iconCls:'icon-cancel',
  381. handler:function(){
  382. $('#Jlayout').layout("remove", "east");
  383. }
  384. }]});
  385. }else{
  386. $('#Jlayout').layout('panel', "east").panel("setTitle", "图形属性设置");
  387. }
  388. if(!comp.style){
  389. comp.style = {};
  390. }
  391. s = comp.style;
  392. var ctp = comp.chartJson.type;
  393. var dt = [];
  394. dt.push({name:'图形标题',col:'title', value:(comp.name?comp.name:""), group:'图形属性', editor:'text'});
  395. if(ctp != 'gauge'){
  396. dt.push({name:'是否隐藏图例',col:'showLegend', value:(comp.chartJson.showLegend?comp.chartJson.showLegend:""), group:'图形属性',editor:{
  397. type:"checkbox",
  398. options:{"on":true, "off":false}
  399. }});
  400. dt.push({name:'图例位置',col:'legendpos', value:(comp.chartJson.legendpos?comp.chartJson.legendpos:""), group:'图形属性',editor:{
  401. type:"combobox",
  402. options:{data:[{text: '右上', value: 'righttop'},{text: '中上', value: 'centertop'},{text: '中下', value: 'centerbottom'}]}
  403. }
  404. });
  405. }
  406. if(ctp != 'gauge'){
  407. dt.push({name:'排列方式',col:'legendLayout', value:(comp.chartJson.legendLayout?comp.chartJson.legendLayout:""), group:'图形属性', editor: {
  408. type:'combobox', options:{data:[{text: '垂直', value: 'vertical'},{text: '水平', value: 'horizontal'}]}
  409. }});
  410. }
  411. if(ctp == "line" || ctp == "area" || ctp == "radar"){
  412. dt.push({name:'是否禁用描点',col:'markerEnabled', value:(comp.chartJson.markerEnabled?comp.chartJson.markerEnabled:""), group:'图形属性',editor:{
  413. type:"checkbox",
  414. options:{"on":true, "off":false}
  415. }});
  416. }
  417. if(ctp == "pie" || ctp == "gauge" || ctp == "radar" || ctp == "map"){ //控制设置图形的marginleft 和 marginright
  418. }else{
  419. dt.push({name:'左间距',col:'marginLeft', value:(comp.chartJson.marginLeft?comp.chartJson.marginLeft:"65"), group:'图形属性', editor:{type:'numberspinner',options:{min:10,max:100,increment:5}}});
  420. dt.push({name:'右间距',col:'marginRight', value:(comp.chartJson.marginRight?comp.chartJson.marginRight:"10"), group:'图形属性', editor:{type:'numberspinner',options:{min:10,max:100,increment:5}}});
  421. }
  422. if(ctp == "line" || ctp == "column" || ctp == "area" || ctp == "bar" || ctp =="scatter" || ctp == "bubble"){
  423. dt.push({name:'是否显示值',col:'dataLabel', value:(comp.chartJson.dataLabel?comp.chartJson.dataLabel:""), group:'图形属性', editor:{
  424. type:"checkbox",
  425. options: {"on":true, "off":false}
  426. }});
  427. }
  428. if(ctp == "pie" || ctp == "gauge" || ctp == "scatter" || ctp == "bubble" || ctp == "radar" || ctp == "map"){
  429. }else{
  430. dt.push({name:'标题',col:'xdispName', value:(comp.chartJson.xcol?comp.chartJson.xcol.xdispName:""), group:'横轴', editor:'text'});
  431. }
  432. if(ctp == 'pie' || ctp =="gauge" || ctp == "scatter" || ctp == "bubble" || ctp == "radar" || ctp == "map"){
  433. }else{
  434. dt.push({name:'显示间隔',col:'tickInterval', value:(comp.chartJson.xcol&&comp.chartJson.xcol.tickInterval?comp.chartJson.xcol.tickInterval:""), group:'横轴', editor:{type:'numberspinner',options:{min:0,max:20,increment:1}}});
  435. }
  436. if(ctp == 'pie' || ctp =="gauge" || ctp == "scatter" || ctp == "bubble" || ctp == "radar" || ctp == "map"){
  437. }else{
  438. dt.push({name:'旋转角度',col:'routeXaxisLable', value:(comp.chartJson.xcol&&comp.chartJson.xcol.routeXaxisLable?comp.chartJson.xcol.routeXaxisLable:""), group:'横轴', editor:{type:'numberspinner',options:{min:0,max:360,increment:5}}});
  439. }
  440. if(ctp == "gauge" || ctp == "scatter" || ctp == "bubble" || ctp == "radar" || ctp == "map"){
  441. }else{
  442. dt.push({name:'取Top',col:'top', value:(comp.chartJson.xcol.top?comp.chartJson.xcol.top:""), group:'横轴', editor:{type:'numberspinner',options:{min:1,max:100,increment:5}}});
  443. }
  444. //散点图或气泡图需要y2轴的属性
  445. if(ctp =="scatter" || ctp == "bubble"){
  446. dt.push({name:'标题',col:'y2dispName', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].ydispName:""), group:'横轴', editor:'text'});
  447. dt.push({name:'单位',col:'unit2', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].unit:""), group:'横轴', editor:'text'});
  448. dt.push({name:'格式化',col:'fmt2', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].fmt:""), group:'横轴', editor:{
  449. type:'combobox',
  450. options:{data:fmtJson}
  451. }});
  452. dt.push({name:'度量比例',col:'rate2', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].rate:""), group:'横轴', editor:{
  453. type:'combobox',
  454. options:{data:kpirate}
  455. }});
  456. }
  457. if(ctp != 'pie' ){
  458. dt.push({name:'标题',col:'ydispName', value:(comp.kpiJson[0]!=null?comp.kpiJson[0].ydispName:""), group:'纵轴', editor:'text'});
  459. }
  460. dt.push({name:'单位',col:'unit', value:(comp.kpiJson[0]!=null?comp.kpiJson[0].unit:""), group:'纵轴', editor:'text'});
  461. dt.push({name:'格式化',col:'fmt', value:(comp.kpiJson[0]!=null?comp.kpiJson[0].fmt:""), group:'纵轴', editor:{
  462. type:'combobox',
  463. options:{data:fmtJson}
  464. }});
  465. if(ctp == "pie" || ctp == "scatter" || ctp == "bubble" || ctp == "map" || ctp == "radar"){
  466. }else{
  467. dt.push({name:'最小值',col:'min', value:(comp.kpiJson[0]!=null?comp.kpiJson[0].min:""), group:'纵轴', editor:{type:'numberspinner',options:{increment:10}}});
  468. }
  469. if(ctp == "gauge"){
  470. dt.push({name:'最大值',col:'max', value:(comp.kpiJson[0]!=null?comp.kpiJson[0].max:""), group:'纵轴', editor:{type:'numberspinner',options:{increment:10}}});
  471. }
  472. dt.push({name:'度量比例',col:'rate', value:(comp.kpiJson[0]!=null?comp.kpiJson[0].rate:""), group:'纵轴', editor:{
  473. type:'combobox',
  474. options:{data:kpirate}
  475. }});
  476. if(ctp == "pie" || ctp == "map"){
  477. dt.push({name:'是否显示标签',col:'dataLabel', value:(comp.chartJson.dataLabel?comp.chartJson.dataLabel:""), group:'图形属性', editor:{
  478. type:"checkbox",
  479. options: {"on":true, "off":false}
  480. }});
  481. if(ctp == "pie"){
  482. dt.push({name:'标签显示内容',col:'labelType', value:(comp.chartJson.labelType?comp.chartJson.labelType:""), group:'图形属性', editor:{
  483. type:"combobox",
  484. options: {"data":[{"text":"名称","value":"n"},{"text":"名称+值","value":"nv"},{"text":"名称+比例","value":"np"}]}
  485. }});
  486. }
  487. }
  488. if((ctp == "column" || ctp == "line") && (comp.chartJson.typeIndex=="2" || comp.chartJson.typeIndex=="4")){ //双坐标设置第二坐标
  489. dt.push({name:'标题',col:'y2dispName', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].ydispName:""), group:'第二纵轴', editor:'text'});
  490. dt.push({name:'单位',col:'unit2', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].unit:""), group:'第二纵轴', editor:'text'});
  491. dt.push({name:'格式化',col:'fmt2', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].fmt:""), group:'第二纵轴', editor:{
  492. type:'combobox',
  493. options:{data:fmtJson}
  494. }});
  495. dt.push({name:'度量比例',col:'rate2', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].rate:""), group:'第二纵轴', editor:{
  496. type:'combobox',
  497. options:{data:kpirate}
  498. }});
  499. dt.push({name:'合并数据',col:'mergeData', value:(comp.kpiJson[1]!=null?comp.kpiJson[1].mergeData:""), group:'第二纵轴', editor:{
  500. type:"checkbox",
  501. options: {"on":true, "off":false}
  502. }});
  503. }
  504. $('#compSet').propertygrid({
  505. showGroup:true,
  506. border:false,
  507. showHeader:false,
  508. fitColumns:false,
  509. scrollbarSize: 0,
  510. onAfterEdit: function(rowIndex,rowData,changes){
  511. var val = rowData.value;
  512. var col = rowData.col;
  513. if(col == "showLegend" || col == "legendLayout" || col == "legendpos" || col == "dataLabel" || col == "markerEnabled" || col == "marginLeft" || col == "marginRight"){
  514. if(comp.chartJson[col]==undefined){
  515. comp.chartJson[col] = "";
  516. }
  517. if(comp.chartJson[col] == val){ //值未改变
  518. return;
  519. }
  520. comp.chartJson[col] = val;
  521. chartview(comp, comp.id);
  522. }else if(col == "tickInterval" || col == "routeXaxisLable" || col == "xdispName" || col == "top"){
  523. if(comp.chartJson.xcol[col]==undefined){
  524. comp.chartJson.xcol[col] = "";
  525. }
  526. if(comp.chartJson.xcol[col] == val){ //值未改变
  527. return;
  528. }
  529. comp.chartJson.xcol[col] = val;
  530. chartview(comp, comp.id);
  531. }else if(col == "ydispName" || col == "unit" || col == "fmt" || col == "min" || col == "max" || col == "rate"){
  532. var o = comp.kpiJson[0];
  533. if(o[col]==undefined){
  534. o[col] = "";
  535. }
  536. if(o[col] == val){ //值未改变
  537. return;
  538. }
  539. o[col] = val;
  540. chartview(comp, comp.id);
  541. }else if(col == "y2dispName" || col == "unit2" || col == "fmt2" || col == "rate2" || col == "mergeData"){ //处理y2col y2轴
  542. var o = comp.kpiJson[1];
  543. if(col == "y2dispName"){
  544. if(o.ydispName == val){ //值未改变
  545. return;
  546. }
  547. o.ydispName = val;
  548. }else if(col == "unit2"){
  549. if(o.unit == val){ //值未改变
  550. return;
  551. }
  552. o.unit = val;
  553. }else if(col == "fmt2"){
  554. if(o.fmt == val){ //值未改变
  555. return;
  556. }
  557. o.fmt = val;
  558. }else if(col == "rate2"){
  559. if(o.rate == val){ //值未改变
  560. return;
  561. }
  562. o.rate = val;
  563. }else if(col == "mergeData"){
  564. if(o.mergeData == val){ //值未改变
  565. return;
  566. }
  567. o.mergeData = val;
  568. }
  569. chartview(comp, comp.id);
  570. }else if(col == "title"){
  571. comp.name = val;
  572. $("#c_"+comp.id + " div.ctit h5").text(val);
  573. }else{
  574. s[col] = val;
  575. }
  576. curTmpInfo.isupdate = true;
  577. },
  578. data:dt
  579. });
  580. }
  581. function chartmenu(ts, id, tp, name, compId){
  582. var offset = $(ts).offset();
  583. //放入临时对象中,方便下次获取
  584. curTmpInfo.ckid = id;
  585. curTmpInfo.tp = tp;
  586. curTmpInfo.compId = compId;
  587. curTmpInfo.dimname = name;
  588. if(tp == 'ycol' || tp == 'y2col' || tp=='y3col'){
  589. $("#chartoptmenu").menu("enableItem", $("#m_set"));
  590. }else{
  591. $("#chartoptmenu").menu("disableItem", $("#m_set"));
  592. }
  593. $("#chartoptmenu").menu("show", {left:offset.left, top:offset.top - 100});
  594. }
  595. function delChartKpiOrDim(){
  596. var tp = curTmpInfo.tp;
  597. var compId = curTmpInfo.compId;
  598. var id = curTmpInfo.ckid;
  599. var json = findCompById(compId);
  600. if(tp == 'xcol'){
  601. json.chartJson.xcol = {};
  602. $("#chartData #xcol").html("<span class=\"charttip\">将维度拖到这里</span>");
  603. curTmpInfo.isupdate = true;
  604. chartview(json, compId);
  605. }
  606. if(tp == 'ycol'){
  607. json.chartJson.ycol = {};
  608. if(json.kpiJson.length > 1){
  609. json.kpiJson[0] = null;
  610. }else{
  611. json.kpiJson = [];
  612. }
  613. $("#chartData #ycol").html("<span class=\"charttip\">将度量拖到这里</span>");
  614. }
  615. if(tp == 'y2col'){
  616. if(json.kpiJson.length > 1){
  617. json.kpiJson[1] = null;
  618. }else{
  619. json.kpiJson = [];
  620. }
  621. if(json.chartJson.type == 'line' || json.chartJson.type == 'column'){
  622. chartview(json, compId);
  623. }
  624. $("#chartData #y2col").html("<span class=\"charttip\">将度量拖到这里</span>");
  625. }
  626. if(tp == 'y3col'){
  627. json.kpiJson[2] = null;
  628. $("#chartData #y3col").html("<span class=\"charttip\">将度量拖到这里</span>");
  629. }
  630. if(tp == 'scol'){
  631. json.chartJson.scol = {};
  632. $("#chartData #scol").html("<span class=\"charttip\">将维度拖到这里</span>");
  633. curTmpInfo.isupdate = true;
  634. chartview(json, compId);
  635. }
  636. }
  637. function chartsort(sorttp){
  638. var tp = curTmpInfo.tp;
  639. var compId = curTmpInfo.compId;
  640. var id = curTmpInfo.ckid;
  641. var json = findCompById(compId);
  642. if(tp == 'xcol'){
  643. //清除度量排序,因为度量排序最优先
  644. delete json.kpiJson[0].sort;
  645. json.chartJson.xcol.dimord = sorttp;
  646. }
  647. if(tp == 'ycol'){
  648. json.kpiJson[0].sort = sorttp;
  649. }
  650. if(tp == 'scol'){
  651. //清除度量排序
  652. delete json.kpiJson[0].sort;
  653. json.chartJson.scol.dimord = sorttp;
  654. }
  655. curTmpInfo.isupdate = true;
  656. chartview(json, compId);
  657. }
  658. function setChartKpi(){
  659. var tp = curTmpInfo.tp;
  660. if(tp == 'xcol' || tp == 'scol'){
  661. return;
  662. }
  663. var dimid = curTmpInfo.ckid;
  664. var compId = curTmpInfo.compId.replace("T", "");
  665. var name = curTmpInfo.dimname;
  666. //获取组件的JSON对象
  667. var comp = findCompById(compId);
  668. var kpi = null;
  669. if(tp == 'ycol'){
  670. kpi = comp.kpiJson[0];
  671. }else if(tp == 'y2col'){
  672. kpi = comp.kpiJson[1];
  673. }else if(tp == 'y3col'){
  674. kpi = comp.kpiJson[2];
  675. }
  676. var ctx = "<div style='line-height:25px; margin:5px;'>度量名称:"+kpi.kpi_name+"<br>所 属 表: "+comp.tname+"<br>度量单位:<select id=\"kpiunit\" name=\"kpiunit\"><option value='1'></option><option value='1000'>千</option><option value='10000'>万</option><option value='1000000'>百万</option><option value='100000000'>亿</option></select>"+kpi.unit+"<br>格 式 化:"+
  677. "<select id=\"fmt\" name=\"fmt\"><option value=\"\"></option><option value=\"#,###,##0\">整数</option><option value=\"###,##0.0\">小数</option><option value=\"0.00%\">百分比</option></select>" + "</div>";
  678. $('#pdailog').dialog({
  679. title: '度量属性',
  680. width: 280,
  681. height: 260,
  682. closed: false,
  683. cache: false,
  684. modal: true,
  685. content: ctx,
  686. toolbar:null,
  687. buttons:[{
  688. text:'确定',
  689. iconCls:'icon-ok',
  690. handler:function(){
  691. kpi.fmt = $("#pdailog #fmt").val();
  692. kpi.rate = Number($("#pdailog #kpiunit").val());
  693. $('#pdailog').dialog('close');
  694. curTmpInfo.isupdate = true;
  695. chartview(comp, compId);
  696. }
  697. },{
  698. text:'取消',
  699. iconCls:"icon-cancel",
  700. handler:function(){
  701. $('#pdailog').dialog('close');
  702. }
  703. }]
  704. });
  705. $("#pdailog #fmt").find("option[value='"+kpi.fmt+"']").attr("selected",true);
  706. $("#pdailog #kpiunit").find("option[value='"+kpi.rate+"']").attr("selected",true);
  707. }
  708. function findDimById(dimId, dims){
  709. var ret = null;
  710. if(!dims || dims == null){
  711. return ret;
  712. }
  713. for(var i=0; i<dims.length; i++){
  714. if(dims[i].id == dimId){
  715. ret = dims[i];
  716. break;
  717. }
  718. }
  719. return ret;
  720. }
  721. //设置系列颜色
  722. function setSeriesColor(a, b, c, d, e, compId){
  723. var comp = findCompById(compId);
  724. if(comp.chartJson.type == "pie" || comp.chartJson.type == "map"){
  725. return;
  726. }
  727. $.getJSON("chartColors.action", {}, function(dt){
  728. var strs = [];
  729. for(i=0;i<dt.length;i++){
  730. if(comp.colors && i+1 == comp.colors[d]){
  731. strs.push("<span class=\"selcolor\">");
  732. }
  733. strs.push("<span style=\"background-color:"+dt[i]+";\" idx=\""+(i + 1)+"\" class=\"seriesColor"+"\"></span>");
  734. if(comp.colors && i+1 == comp.colors[d]){
  735. strs.push("</span>");
  736. }
  737. }
  738. var ctx = strs.join(" ")+"<br/><button class=\"btn btn-info btn-sm\">使用默认色</button>";
  739. $('#pdailog').dialog({
  740. title: d + ' - 设置系列颜色',
  741. width: 380,
  742. height: 240,
  743. closed: false,
  744. cache: false,
  745. modal: true,
  746. toolbar:null,
  747. content: ctx,
  748. buttons:[{
  749. text:'取消',
  750. handler:function(){
  751. $('#pdailog').dialog('close');
  752. }
  753. }]
  754. });
  755. $("#pdailog .seriesColor").click(function(){
  756. var colorIdx = $(this).attr("idx");
  757. if(!comp.colors){
  758. comp.colors = {};
  759. }
  760. comp.colors[d] = colorIdx;
  761. curTmpInfo.isupdate = true;
  762. $('#pdailog').dialog('close');
  763. chartview(comp, compId);
  764. });
  765. $("#pdailog button").click(function(){
  766. if(comp.colors){
  767. delete comp.colors[d];
  768. $('#pdailog').dialog('close');
  769. chartview(comp, compId);
  770. }
  771. });
  772. });
  773. }