statis.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. var host = document.domain; // 或 window.localtion.host
  7. var API = 'http://' + host + '/PetMulti/Gameserver/Amfphp/Services/StatServer.php';
  8. window.myDateStr = '20150526';
  9. window.myZoneStr = '1';
  10. // 请求数据
  11. function GetData(statType) {
  12. var req = {
  13. statType: statType,
  14. dateType: window.myDateTypeStr,
  15. dateIndex: window.myDateStr,
  16. zoneid: window.myZoneStr
  17. };
  18. $.ajax({
  19. type: "post",
  20. url: API,
  21. data: JSON.stringify(req),
  22. dataType: 'JSON',
  23. contentType: 'application/json',
  24. processData: false,
  25. success: function (resp) {
  26. RenderData(resp, getTitleText);
  27. },
  28. error: function (XMLHttpRequest, textStatus, errorThrown) {
  29. alert("err:" + XMLHttpRequest.status + XMLHttpRequest.readyState + XMLHttpRequest.responseText);
  30. }
  31. });
  32. }
  33. // 渲染
  34. function RenderData(respData, getTitleText) {
  35. //Get the context of the canvas element we want to select
  36. $("#myChart").remove();
  37. $("#chartContainer").append('<canvas id="myChart" style="width:100%;height:100%;border: 1px solid red;"></canvas>');
  38. ctx = document.getElementById("myChart").getContext("2d");
  39. new Chart(ctx, {
  40. type: 'bar',
  41. data: respData,
  42. options: {
  43. // Elements options apply to all of the options unless overridden in a dataset
  44. // In this case, we are setting the border of each bar to be 2px wide and green
  45. animation: false,
  46. elements: {
  47. rectangle: {
  48. borderWidth: 2,
  49. borderColor: 'rgb(0, 255, 0)',
  50. borderSkipped: 'bottom'
  51. }
  52. },
  53. responsive: true,
  54. scaleIntegersOnly: true,
  55. legend: {
  56. position: 'top',
  57. scale: 1
  58. },
  59. title: {
  60. display: true,
  61. text: getTitleText()
  62. }
  63. }
  64. });
  65. }