Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Flotr2PieChart.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.charting;
  17. import java.text.MessageFormat;
  18. import com.gitblit.utils.StringUtils;
  19. /**
  20. * Implementation of a Pie chart using the flotr2 library
  21. *
  22. * @author Tim Ryan
  23. *
  24. */
  25. public class Flotr2PieChart extends Chart {
  26. private static final long serialVersionUID = 1L;
  27. public Flotr2PieChart(String tagId, String title, String keyName, String valueName) {
  28. super(tagId, title, keyName, valueName);
  29. }
  30. @Override
  31. protected void appendChart(StringBuilder sb) {
  32. String dName = "data_" + dataName;
  33. line(sb, "var selected_" + dataName + " = null;");
  34. line(sb, MessageFormat.format("var {0} = Flotr.draw(document.getElementById(''{1}''),", dName, tagId));
  35. // Add the data
  36. line(sb, "[");
  37. for (int i = 0; i < values.size(); i++) {
  38. ChartValue value = values.get(i);
  39. if(i > 0){
  40. sb.append(",");
  41. }
  42. line(sb, MessageFormat.format("'{'data : [ [0, {0}] ], label : ''{1}'', color: ''{2}'' '}'", Float.toString(value.value), value.name, StringUtils.getColor(value.name)));
  43. }
  44. line(sb, "]");
  45. // Add the options
  46. line(sb, ", {");
  47. line(sb, MessageFormat.format("title : ''{0}'',", title));
  48. line(sb, "fontSize : 2,");
  49. line(sb, "pie : {");
  50. line(sb, " show : true,");
  51. line(sb, " labelFormatter : function (pie, slice) {");
  52. line(sb, " if(slice / pie > .05)");
  53. line(sb, " return Math.round(slice / pie * 100).toString() + \"%\";");
  54. line(sb, " }");
  55. line(sb, "}");
  56. line(sb, ", mouse: {");
  57. line(sb, " track: true,");
  58. line(sb, " lineColor: '#002060',");
  59. line(sb, " trackFormatter: function (obj)");
  60. line(sb, " {");
  61. line(sb, " selected_" + dataName + " = obj.series.label;");
  62. line(sb, " return obj.series.label + \": \" + parseInt(obj.y) + \" (\" + Math.round(obj.fraction * 100) + \"%)\";" );
  63. line(sb, " }");
  64. line(sb, "}");
  65. line(sb, ", xaxis: {");
  66. line(sb, " margin: false,");
  67. line(sb, " showLabels: false,");
  68. line(sb, " showMinorLabels: false");
  69. line(sb, "}");
  70. line(sb, ", yaxis: {");
  71. line(sb, " margin: false,");
  72. line(sb, " min: 20,");
  73. line(sb, " showLabels: false,");
  74. line(sb, " showMinorLabels: false");
  75. line(sb, "}");
  76. line(sb, ", grid: {");
  77. line(sb, " verticalLines: false,");
  78. line(sb, " minorVerticalLines: null,");
  79. line(sb, " horizontalLines: false,");
  80. line(sb, " minorHorizontalLines: null,");
  81. line(sb, " outlineWidth: 0");
  82. line(sb, "}");
  83. line(sb, ", legend: {");
  84. if(showLegend){
  85. line(sb, " show: true");
  86. }
  87. else {
  88. line(sb, " show: false");
  89. }
  90. line(sb, "}");
  91. line(sb, "});");
  92. if(clickUrl != null && clickUrl.isEmpty() == false){
  93. line(sb, MessageFormat.format("Flotr.EventAdapter.observe(document.getElementById(''{0}''), ''flotr:click'', function (mouse, a, b, c) '{'", tagId));
  94. line(sb, " window.location.href = \"" + clickUrl + "\" + selected_" + dataName + ";");
  95. line(sb, "});");
  96. }
  97. }
  98. }