Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('input#date-submit').on('click',function(){
- $.ajax({
- url: "http://localhost/chartjs/num_of_issues.php",
- type: "GET",// request data from a specific resouce
- success: function(data){
- console.log(data);//print out data
- Date.prototype.addDays = function(days)
- {
- var dat = new Date(this.valueOf())
- dat.setDate(dat.getDate() + days);
- return dat;
- }
- function getDates(startDate, stopDate) {
- var dateArray = new Array();
- var currentDate = startDate;
- while (currentDate <= stopDate) {
- dateArray.push(currentDate)
- currentDate = currentDate.addDays(1);
- }
- return dateArray;
- }
- var dateArray = getDates(new Date($('input#select-date').val()), new Date($('input#select-date').val()));
- var item= {
- issue : []
- }
- for(var i in data) {
- if(data[i].date==dateArray){
- item.issue.push(data[i].issues);
- }
- }
- var chartdata = {
- labels: ["Enterprise Syetem","Security Services","End User Services","Managed Services","Mobility Services"],
- datasets : [
- {
- backgroundColor: [
- "#3e0272",
- "#C90F2B",
- "#E8B52D",
- "#128B48",
- "#0b3d82"],
- data:item.issue
- }
- ]
- };
- var ctx = $("#chartcanvas");
- var option2 = {
- responsive: true,
- legend:{
- display:true,
- position:"bottom"
- },
- title:{
- display:true,
- position:'top',
- text:"General issues",
- fontSize:20
- }
- };
- if(window.bar!=undefined){
- window.bar.destroy();
- }
- window.bar = new Chart(ctx, {
- type: 'pie',
- data: chartdata,
- options: option2
- });
- },
- error: function(data) {
- console.log(data);
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement