You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Flotr2Charts.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 javax.servlet.ServletContext;
  18. import org.apache.wicket.markup.html.IHeaderResponse;
  19. import org.apache.wicket.protocol.http.WebApplication;
  20. /**
  21. * Concrete class for Flotr2 charts
  22. *
  23. * @author Tim Ryan
  24. *
  25. */
  26. public class Flotr2Charts extends Charts {
  27. private static final long serialVersionUID = 1L;
  28. @Override
  29. public void renderHead(IHeaderResponse response) {
  30. // add Google Chart JS API reference
  31. ServletContext servletContext = WebApplication.get().getServletContext();
  32. String contextPath = servletContext.getContextPath();
  33. response.renderJavascriptReference(contextPath + "/bootstrap/js/jquery.js");
  34. response.renderJavascriptReference(contextPath + "/flotr2/flotr2.min.js");
  35. response.renderCSSReference(contextPath + "/flotr2/flotr2.custom.css");
  36. // prepare draw chart function
  37. StringBuilder sb = new StringBuilder();
  38. line(sb, "$( document ).ready(function() {");
  39. // add charts to header
  40. for (Chart chart : charts) {
  41. chart.appendChart(sb);
  42. }
  43. // end draw chart function
  44. line(sb, "});");
  45. response.renderJavascript(sb.toString(), null);
  46. }
  47. @Override
  48. public Chart createPieChart(String tagId, String title, String keyName,
  49. String valueName) {
  50. return new Flotr2PieChart(tagId, title, keyName, valueName);
  51. }
  52. @Override
  53. public Chart createLineChart(String tagId, String title, String keyName,
  54. String valueName) {
  55. return new Flotr2LineChart(tagId, title, keyName, valueName);
  56. }
  57. @Override
  58. public Chart createBarChart(String tagId, String title, String keyName,
  59. String valueName) {
  60. return new Flotr2BarChart(tagId, title, keyName, valueName);
  61. }
  62. }