Advertisement
Guest User

Untitled

a guest
May 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. $('input#date-submit').on('click',function(){
  2. $.ajax({
  3. url: "http://localhost/chartjs/num_of_issues.php",
  4. type: "GET",// request data from a specific resouce
  5. success: function(data){
  6. console.log(data);//print out data
  7.  
  8. Date.prototype.addDays = function(days)
  9. {
  10. var dat = new Date(this.valueOf())
  11. dat.setDate(dat.getDate() + days);
  12. return dat;
  13. }
  14.  
  15. function getDates(startDate, stopDate) {
  16. var dateArray = new Array();
  17. var currentDate = startDate;
  18. while (currentDate <= stopDate) {
  19. dateArray.push(currentDate)
  20. currentDate = currentDate.addDays(1);
  21. }
  22. return dateArray;
  23. }
  24. var dateArray = getDates(new Date($('input#select-date').val()), new Date($('input#select-date').val()));
  25.  
  26. var item= {
  27. issue : []
  28. }
  29.  
  30. for(var i in data) {
  31. if(data[i].date==dateArray){
  32.  
  33.  
  34. item.issue.push(data[i].issues);
  35. }
  36. }
  37.  
  38.  
  39.  
  40. var chartdata = {
  41. labels: ["Enterprise Syetem","Security Services","End User Services","Managed Services","Mobility Services"],
  42. datasets : [
  43. {
  44. backgroundColor: [
  45. "#3e0272",
  46. "#C90F2B",
  47. "#E8B52D",
  48. "#128B48",
  49. "#0b3d82"],
  50. data:item.issue
  51. }
  52. ]
  53. };
  54.  
  55. var ctx = $("#chartcanvas");
  56. var option2 = {
  57. responsive: true,
  58. legend:{
  59. display:true,
  60. position:"bottom"
  61. },
  62. title:{
  63. display:true,
  64. position:'top',
  65. text:"General issues",
  66. fontSize:20
  67. }
  68. };
  69.  
  70. if(window.bar!=undefined){
  71. window.bar.destroy();
  72. }
  73. window.bar = new Chart(ctx, {
  74. type: 'pie',
  75. data: chartdata,
  76. options: option2
  77. });
  78.  
  79. },
  80. error: function(data) {
  81. console.log(data);
  82. }
  83.  
  84. });
  85. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement