/survey/src/main/webapp/app/survey/survey/include_answer.ftl

https://github.com/AAATEAM/survey · Freemarker Template · 160 lines · 125 code · 35 blank · 0 comment · 16 complexity · 8a8fc214ce8c7d22261b807ee9299feb MD5 · raw file

  1. <script src="common/raphael212/raphael.min.js" type="text/javascript"></script>
  2. <script src="common/elycharts/elycharts.js" type="text/javascript"></script>
  3. <script>
  4. </script>
  5. <style>
  6. .choiceitem0{
  7. background-color: #E5E5E5;
  8. }
  9. .choiceitem1{
  10. background-color: #EFEFEF;
  11. }
  12. </style>
  13. <div id="test"></div>
  14. <div class="panel panel-primary" style="margin-top: 5px; margin-left:15px;">
  15. <div class="panel-heading"><strong>Result Detail</strong></div>
  16. <div class="panel-body">
  17. <#if (rhs["singleitems"]?size > 0) >
  18. <table class="table table-condensed table-bordered table-striped">
  19. <#assign i = 0 >
  20. <#list rhs["singleitems"]?keys as itemid>
  21. <tr>
  22. <#assign singleitem = rhs["singleitems"][itemid][0] />
  23. <td>
  24. <strong>${i+1}.&nbsp;${singleitem.item.content}</strong><br />
  25. <div id="chart_${i}"></div>
  26. </td>
  27. </tr>
  28. <#assign i = i + 1 >
  29. </#list>
  30. </table>
  31. </#if>
  32. </div>
  33. </div>
  34. <script>
  35. var result = [];
  36. <!--dialog数据 多个-->
  37. <#if (rhs["singleitems"]?size > 0) >
  38. <#assign i = 0 >
  39. <#list rhs["singleitems"]?keys as itemid>
  40. <#assign singleitem = rhs["singleitems"][itemid][0] />
  41. var labels = [], users = []; //选项, 每项回答的用户
  42. <#list singleitem.item.choiceitem?sort_by("id") as choiceitem>
  43. labels[${choiceitem_index}] = "${choiceitem.value}";
  44. var tmpusr = [];
  45. <#assign ui = 0 >
  46. <#list rhs["singleitems"][itemid] as result>
  47. <#if result.answer?exists && result.answer?string == choiceitem.refid?string>
  48. tmpusr[${ui}] = "${result.user}";
  49. <#assign ui = ui + 1 >
  50. </#if>
  51. </#list>
  52. users[${choiceitem_index}] = tmpusr;
  53. </#list>
  54. result[${i}] = {"labels" : labels, "users" : users};
  55. <#assign i = i + 1 >
  56. </#list>
  57. </#if>
  58. $(document).ready(function(){
  59. for(var i = 0; i < result.length; i ++){
  60. var elobj = $("#chart_" + i);
  61. if(!createPie(elobj,i)){
  62. elobj.html("暂无人回答此问题。 ");
  63. }
  64. }
  65. });
  66. function createPie(elobj,index){
  67. var tusers = result[index].users;
  68. var values = [];
  69. var flag = false;
  70. var count = 0; //回答问题的人数
  71. for(var i = 0; i < tusers.length; i++) {
  72. values[i] = tusers[i].length;
  73. if(tusers[i].length > 0) flag = true;
  74. count += tusers[i].length;
  75. }
  76. if(!flag) return false;
  77. var legend = result[index].labels;
  78. var labels = []; //显示百分比
  79. for(var i = 0; i < values.length; i++) {
  80. labels[i] = (values[i] / count * 100).toFixed(2) + "%" ;
  81. }
  82. //计算 legend 宽
  83. var tmpleg = "";
  84. for(var i = 0; i < legend.length; i++){
  85. if(tusers[i].length > 0 ) legend[i] = legend[i] + " ["+tusers[i]+"]";
  86. }
  87. $.elycharts.templates['pie_basic_1'] = {
  88. type : "pie",
  89. //style : {"background-color" : "black"},
  90. gridNX: 40,
  91. defaultSeries :{
  92. label:{ active : true,props : {fill : "white"}},
  93. plotProps:{ stroke : "white","stroke-width" : 2,opacity : 0.8},
  94. highlight : {move : 20},
  95. tooltip : {frameProps : {opacity : 0.5}},
  96. startAnimation : {active : true,type : "grow"}
  97. },
  98. features : {
  99. legend :{
  100. itemWidth: "auto",
  101. horizontal : false,height : 80, x : 10,y : 10, dotType : "circle",
  102. dotProps : {stroke : "white","stroke-width" : 0},
  103. }
  104. }
  105. };
  106. var width = $(window).width();
  107. var tips = [];
  108. for(var i = 0; i < tusers.length; i++){
  109. if(tusers[i].length > 0 ) tips[i] = tusers[i].join(",");
  110. }
  111. elobj.chart({
  112. template : "pie_basic_1",
  113. //margins : [150, 0, 0, 700],
  114. margins : [70, 0, 0, 0],
  115. //width: 500,
  116. height: 300,
  117. values : {serie1 : values},
  118. labels : labels,
  119. legend : legend,
  120. tooltips : {serie1: tips},
  121. defaultSeries: {values:[{plotProps:{fill: "red"}},{plotProps:{fill: "blue"}},{plotProps:{fill: "green"}},{plotProps:{fill: "gray"}}]}
  122. });
  123. return true;
  124. }
  125. </script>