2016-01-06 40 views
0

我想根据日期(dd:mm:yyyy)选取器中选择的日期更改甘特图数据。如何根据选择的日期更改甘特图数据

这是我的屏幕截图。 Gantt Chart

HTML代码:

<div class="col-sm-8" ng-controller="ReportsController"> 
<div class="col-sm-12 page-top-actions"> 
    <div class="col-sm-3 day-wise-report"> 
     <input type="date" name="report" tooltip="Day"> 
    </div> 
    <div class="col-sm-3 show-report"> 
     <button class="btn btn-default" type="submit">Show Report</button> 
    </div> 
</div> 
<select ng-init="selectedChart.chart = chartOptions[0]; updateChart()" ng-model="selectedChart.chart" 
     ng-change="updateChart()" ng-options="c.name for c in chartOptions track by c.id"></select> 
<fusioncharts 
     id="exampleId" 
     width="800" 
     height="400" 
     type="gantt" 
     datasource="{{productivityReportData}}"> 
</fusioncharts> 

JavaScript代码:

app.controller('ReportsController', ['$scope', function ($scope) { 

    $scope.chartOptions = [{ 
     id: 1, 
     name: "Day 1" 
    }, { 
     id: 2, 
     name: "Day 2" 
    }]; 

    $scope.reportsDataSource = { 

     "chart": { 
      "dateformat": "mm/dd/yyyy hh:mm:ss", 
      "outputDateFormat": "ddds mn l, yyyy hh12:mn ampm", 
      "caption": "Operator Productivity", 
      "subCaption": "Day 1", 
      "slackFillColor": "f44336", 
      "showSlackAsFill": "1", 
      "canvasBorderAlpha": "30", 
      "plottooltext": "$processName{br} $label: starting time $start{br} - ending time $end", 
      "theme": "fint" 
     }, 
     "categories": [ 
      { 
       "category": [ 
        { 
         "start": "09:00:00", 
         "end": "18:00:00", 
         "label": "Activity Timeline" 
        } 
       ] 
      }, 
      { 
       "align": "center", 
       "category": [ 
        { 
         "start": "11:00:00", 
         "end": "10:59:59", 
         "label": "9am-11am" 
        }, 
        { 
         "start": "11:00:00", 
         "end": "12:59:59", 
         "label": "11am-1pm" 
        }, 
        { 
         "start": "13:00:00", 
         "end": "13:59:59", 
         "label": "1pm-2pm" 
        }, 
        { 
         "start": "14:00:00", 
         "end": "15:59:59", 
         "label": "2pm-4pm" 
        }, 
        { 
         "start": "16:00:00", 
         "end": "17:59:59", 
         "label": "4pm-6pm" 
        } 

       ] 
      } 
     ], 
     "processes": { 
      "fontsize": "12", 
      "isbold": "1", 
      "align": "left", 
      "headertext": "Operators", 
      "headerfontsize": "14", 
      "headervalign": "middle", 
      "headeralign": "left", 
      "process": [ 
       { 
        "label": "Karthik", 
        "id": "EMP121" 
       }, 
       { 
        "label": "David.G", 
        "id": "EMP122" 
       }, 
       { 
        "label": "Mary.P", 
        "id": "EMP123" 
       }, 
       { 
        "label": "Andrew.H", 
        "id": "EMP124" 
       }, 
       { 
        "label": "Neil.M", 
        "id": "EMP125" 
       } 
      ] 
     }, 
     "tasks": { 
      "showlabels": "1", 
      "task": [ 
       { 
        "processid": "EMP121", 
        "start": "09:00:00", 
        "end": "10:00:00", 
        "label": "Activity1" 


       }, 
       { 
        "processid": "EMP121", 
        "start": "15:00:00", 
        "end": "14:30:00", 
        "label": "Activity2" 
       }, 
       { 
        "processid": "EMP122", 
        "start": "10:00:00", 
        "end": "16:34:17", 
        "percentComplete": "75", 
        "label": "Activity3" 
       }, 
       { 
        "processid": "EMP123", 
        "start": "11:00:00", 
        "end": "12:10:00", 
        "label": "Activity4" 
       }, 
       { 
        "processid": "EMP123", 
        "start": "15:00:00", 
        "end": "17:32:00", 
        "label": "Activity 2" 
       }, 
       { 
        "processid": "EMP124", 
        "start": "10:30:00", 
        "end": "12:36:00", 
        "label": "Activity 2" 
       }, 
       { 
        "processid": "EMP125", 
        "start": "14:00:00", 
        "end": "15:32:00", 
        "label": "Activity 1" 
       } 
      ] 
     } 

    }; 
    $scope.reportsDataSource2 = { 

     "chart": { 
      "dateformat": "mm/dd/yyyy hh:mm:ss", 
      "outputDateFormat": "ddds mnl, yyyy hh12:mn ampm", 
      "caption": "Operator Productivity", 
      "subCaption": "Day 2", 
      "slackFillColor": "f44336", 
      "showSlackAsFill": "1", 
      "canvasBorderAlpha": "30", 
      "plottooltext": "$processName{br} $label: starting time $start{br} - ending time $end", 
      "theme": "fint" 
     }, 
     "categories": [ 
      { 
       "category": [ 
        { 
         "start": "09:00:00", 
         "end": "18:00:00", 
         "label": "Activity Timeline" 
        } 
       ] 
      }, 
      { 
       "align": "center", 
       "category": [ 
        { 
         "start": "09:00:00", 
         "end": "10:59:59", 
         "label": "9am-11am" 
        }, 
        { 
         "start": "11:00:00", 
         "end": "12:59:59", 
         "label": "11am-1pm" 
        }, 
        { 
         "start": "13:00:00", 
         "end": "13:59:59", 
         "label": "1pm-2pm" 
        }, 
        { 
         "start": "14:00:00", 
         "end": "15:59:59", 
         "label": "2pm-4pm" 
        }, 
        { 
         "start": "16:00:00", 
         "end": "17:59:59", 
         "label": "4pm-6pm" 
        } 

       ] 
      } 
     ], 
     "processes": { 
      "fontsize": "12", 
      "isbold": "1", 
      "align": "left", 
      "headertext": "Operators", 
      "headerfontsize": "14", 
      "headervalign": "middle", 
      "headeralign": "left", 
      "process": [ 
       { 
        "label": "Karthik", 
        "id": "EMP121" 
       }, 
       { 
        "label": "David.G", 
        "id": "EMP122" 
       }, 
       { 
        "label": "Mary.P", 
        "id": "EMP123" 
       }, 
       { 
        "label": "Andrew.H", 
        "id": "EMP124" 
       }, 
       { 
        "label": "Neil.M", 
        "id": "EMP125" 
       } 
      ] 
     }, 
     "tasks": { 
      "showlabels": "1", 
      "task": [ 
       { 
        "processid": "EMP121", 
        "start": "09:00:00", 
        "end": "10:00:00", 
        "label": "Activity1" 


       }, 
       { 
        "processid": "EMP121", 
        "start": "15:00:00", 
        "end": "14:30:00", 
        "label": "Activity2" 
       }, 
       { 
        "processid": "EMP122", 
        "start": "10:00:00", 
        "end": "16:34:17", 
        "percentComplete": "75", 
        "label": "Activity3" 
       }, 
       { 
        "processid": "EMP123", 
        "start": "11:00:00", 
        "end": "12:10:00", 
        "label": "Activity4" 
       }, 
       { 
        "processid": "EMP123", 
        "start": "15:00:00", 
        "end": "17:32:00", 
        "label": "Activity 2" 
       }, 
       { 
        "processid": "EMP124", 
        "start": "10:30:00", 
        "end": "12:36:00", 
        "label": "Activity 2" 
       }, 
       { 
        "processid": "EMP125", 
        "start": "14:00:00", 
        "end": "15:32:00", 
        "label": "Activity 1" 
       } 
      ] 
     } 

    }; 
    $scope.updateChart = function() { 

     if ($scope.selectedChart.chart === undefined || $scope.selectedChart.chart.id === 1) { 
      $scope.productivityReportData = $scope.reportsDataSource; 
     } 

     if ($scope.selectedChart.chart !== undefined && $scope.selectedChart.chart.id === 2) { 
      $scope.productivityReportData = $scope.reportsDataSource2; 
     } 
    }; 

}]); 

请让我知道如何与HTML集成和生成数据的日期,月份和年份选择。

回答

0

为了更改日期选择图表你必须添加eventlistener到<input type="date" name="report" tooltip="Day"></div>。 我已更改您的代码并更新了代码。

var app = angular.module('myApp', ["ng-fusioncharts"]), 
 
\t globalContainer = {}, 
 
\t _intUpdate; 
 

 
app.controller('ReportsController', ['$scope', function ($scope) { 
 

 
    $scope.chartOptions = [{ 
 
     id: 1, 
 
     name: "Day 1" 
 
    }, { 
 
     id: 2, 
 
     name: "Day 2" 
 
    }]; 
 

 
    $scope.reportsDataSource = { 
 

 
     "chart": { 
 
      "dateformat": "mm/dd/yyyy hh:mm:ss", 
 
      "outputDateFormat": "ddds mn l, yyyy hh12:mn ampm", 
 
      "caption": "Operator Productivity", 
 
      "subCaption": "Day 1", 
 
      "slackFillColor": "f44336", 
 
      "showSlackAsFill": "1", 
 
      "canvasBorderAlpha": "30", 
 
      "plottooltext": "$processName{br} $label: starting time $start{br} - ending time $end", 
 
      "theme": "fint" 
 
     }, 
 
     "categories": [ 
 
      { 
 
       "category": [ 
 
        { 
 
         "start": "09:00:00", 
 
         "end": "18:00:00", 
 
         "label": "Activity Timeline" 
 
        } 
 
       ] 
 
      }, 
 
      { 
 
       "align": "center", 
 
       "category": [ 
 
        { 
 
         "start": "11:00:00", 
 
         "end": "10:59:59", 
 
         "label": "9am-11am" 
 
        }, 
 
        { 
 
         "start": "11:00:00", 
 
         "end": "12:59:59", 
 
         "label": "11am-1pm" 
 
        }, 
 
        { 
 
         "start": "13:00:00", 
 
         "end": "13:59:59", 
 
         "label": "1pm-2pm" 
 
        }, 
 
        { 
 
         "start": "14:00:00", 
 
         "end": "15:59:59", 
 
         "label": "2pm-4pm" 
 
        }, 
 
        { 
 
         "start": "16:00:00", 
 
         "end": "17:59:59", 
 
         "label": "4pm-6pm" 
 
        } 
 

 
       ] 
 
      } 
 
     ], 
 
     "processes": { 
 
      "fontsize": "12", 
 
      "isbold": "1", 
 
      "align": "left", 
 
      "headertext": "Operators", 
 
      "headerfontsize": "14", 
 
      "headervalign": "middle", 
 
      "headeralign": "left", 
 
      "process": [ 
 
       { 
 
        "label": "Karthik", 
 
        "id": "EMP121" 
 
       }, 
 
       { 
 
        "label": "David.G", 
 
        "id": "EMP122" 
 
       }, 
 
       { 
 
        "label": "Mary.P", 
 
        "id": "EMP123" 
 
       }, 
 
       { 
 
        "label": "Andrew.H", 
 
        "id": "EMP124" 
 
       }, 
 
       { 
 
        "label": "Neil.M", 
 
        "id": "EMP125" 
 
       } 
 
      ] 
 
     }, 
 
     "tasks": { 
 
      "showlabels": "1", 
 
      "task": [ 
 
       { 
 
        "processid": "EMP121", 
 
        "start": "09:00:00", 
 
        "end": "10:00:00", 
 
        "label": "Activity1" 
 

 

 
       }, 
 
       { 
 
        "processid": "EMP121", 
 
        "start": "15:00:00", 
 
        "end": "14:30:00", 
 
        "label": "Activity2" 
 
       }, 
 
       { 
 
        "processid": "EMP122", 
 
        "start": "10:00:00", 
 
        "end": "16:34:17", 
 
        "percentComplete": "75", 
 
        "label": "Activity3" 
 
       }, 
 
       { 
 
        "processid": "EMP123", 
 
        "start": "11:00:00", 
 
        "end": "12:10:00", 
 
        "label": "Activity4" 
 
       }, 
 
       { 
 
        "processid": "EMP123", 
 
        "start": "15:00:00", 
 
        "end": "17:32:00", 
 
        "label": "Activity 2" 
 
       }, 
 
       { 
 
        "processid": "EMP124", 
 
        "start": "10:30:00", 
 
        "end": "12:36:00", 
 
        "label": "Activity 2" 
 
       }, 
 
       { 
 
        "processid": "EMP125", 
 
        "start": "14:00:00", 
 
        "end": "15:32:00", 
 
        "label": "Activity 1" 
 
       } 
 
      ] 
 
     } 
 

 
    }; 
 
    $scope.reportsDataSource2 = { 
 

 
     "chart": { 
 
      "dateformat": "mm/dd/yyyy hh:mm:ss", 
 
      "outputDateFormat": "ddds mnl, yyyy hh12:mn ampm", 
 
      "caption": "Operator Productivity", 
 
      "subCaption": "Day 2", 
 
      "slackFillColor": "f44336", 
 
      "showSlackAsFill": "1", 
 
      "canvasBorderAlpha": "30", 
 
      "plottooltext": "$processName{br} $label: starting time $start{br} - ending time $end", 
 
      "theme": "fint" 
 
     }, 
 
     "categories": [ 
 
      { 
 
       "category": [ 
 
        { 
 
         "start": "09:00:00", 
 
         "end": "18:00:00", 
 
         "label": "Activity Timeline" 
 
        } 
 
       ] 
 
      }, 
 
      { 
 
       "align": "center", 
 
       "category": [ 
 
        { 
 
         "start": "09:00:00", 
 
         "end": "10:59:59", 
 
         "label": "9am-11am" 
 
        }, 
 
        { 
 
         "start": "11:00:00", 
 
         "end": "12:59:59", 
 
         "label": "11am-1pm" 
 
        }, 
 
        { 
 
         "start": "13:00:00", 
 
         "end": "13:59:59", 
 
         "label": "1pm-2pm" 
 
        }, 
 
        { 
 
         "start": "14:00:00", 
 
         "end": "15:59:59", 
 
         "label": "2pm-4pm" 
 
        }, 
 
        { 
 
         "start": "16:00:00", 
 
         "end": "17:59:59", 
 
         "label": "4pm-6pm" 
 
        } 
 

 
       ] 
 
      } 
 
     ], 
 
     "processes": { 
 
      "fontsize": "12", 
 
      "isbold": "1", 
 
      "align": "left", 
 
      "headertext": "Operators", 
 
      "headerfontsize": "14", 
 
      "headervalign": "middle", 
 
      "headeralign": "left", 
 
      "process": [ 
 
       { 
 
        "label": "Karthik", 
 
        "id": "EMP121" 
 
       }, 
 
       { 
 
        "label": "David.G", 
 
        "id": "EMP122" 
 
       }, 
 
       { 
 
        "label": "Mary.P", 
 
        "id": "EMP123" 
 
       }, 
 
       { 
 
        "label": "Andrew.H", 
 
        "id": "EMP124" 
 
       }, 
 
       { 
 
        "label": "Neil.M", 
 
        "id": "EMP125" 
 
       } 
 
      ] 
 
     }, 
 
     "tasks": { 
 
      "showlabels": "1", 
 
      "task": [ 
 
       { 
 
        "processid": "EMP121", 
 
        "start": "09:00:00", 
 
        "end": "10:00:00", 
 
        "label": "Activity1" 
 

 

 
       }, 
 
       
 
       { 
 
        "processid": "EMP122", 
 
        "start": "10:00:00", 
 
        "end": "16:34:17", 
 
        "percentComplete": "75", 
 
        "label": "Activity3" 
 
       }, 
 
       { 
 
        "processid": "EMP123", 
 
        "start": "11:00:00", 
 
        "end": "12:10:00", 
 
        "label": "Activity4" 
 
       }, 
 
       { 
 
        "processid": "EMP123", 
 
        "start": "15:00:00", 
 
        "end": "17:32:00", 
 
        "label": "Activity 2" 
 
       }, 
 
       { 
 
        "processid": "EMP124", 
 
        "start": "10:30:00", 
 
        "end": "12:36:00", 
 
        "label": "Activity 2" 
 
       }, 
 
       { 
 
        "processid": "EMP125", 
 
        "start": "14:00:00", 
 
        "end": "15:32:00", 
 
        "label": "Activity 1" 
 
       } 
 
      ] 
 
     } 
 

 
    }; 
 
    $scope.updateChart = function() { 
 

 
     if ($scope.selectedChart.chart === undefined || $scope.selectedChart.chart.id === 1) { 
 
      $scope.productivityReportData = $scope.reportsDataSource; 
 
     } 
 

 
     if ($scope.selectedChart.chart !== undefined && $scope.selectedChart.chart.id === 2) { 
 
      $scope.productivityReportData = $scope.reportsDataSource2; 
 
     } 
 
    }; 
 

 
    $scope._intUpdate = _intUpdate = function(){ 
 
    \t $scope.$apply(function(){ 
 
    \t \t $scope.productivityReportData = $scope.reportsDataSource2; \t 
 
\t \t }); \t 
 
    } 
 

 
}]); 
 

 
function updateChart(){ 
 
\t _intUpdate(); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
\t <script src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script> 
 
\t <script src="http://fusioncharts.github.io/angular-fusioncharts/demos/js/angular-fusioncharts.min.js"></script> 
 

 
<div ng-app="myApp"> 
 
    <div class="col-sm-8" ng-controller="ReportsController"> 
 
\t <div class="col-sm-12 page-top-actions"> 
 
\t  <div class="col-sm-3 day-wise-report"> 
 
\t  <input type="date" name="report" tooltip="Day" onchange="updateChart()"> 
 
\t  </div> 
 
\t  <div class="col-sm-3 show-report"> 
 
\t   <button class="btn btn-default" type="submit">Show Report</button> 
 
\t  </div> 
 
\t </div> 
 
\t <select ng-init="selectedChart.chart = chartOptions[0]; updateChart()" ng-model="selectedChart.chart" 
 
\t   ng-change="updateChart()" ng-options="c.name for c in chartOptions track by c.id"></select> 
 

 
\t <div fusioncharts 
 
\t   id="exampleId" 
 
\t   width="800" 
 
\t   height="400" 
 
\t   type="gantt" 
 
\t   datasource="{{productivityReportData}}"> 
 
\t </div> 
 
</div>