Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何减少谷歌图表功能代码?_Javascript_Angularjs_Charts_Google Visualization - Fatal编程技术网

Javascript 如何减少谷歌图表功能代码?

Javascript 如何减少谷歌图表功能代码?,javascript,angularjs,charts,google-visualization,Javascript,Angularjs,Charts,Google Visualization,如果可能的话,减少代码行。我得到的结果很好。请指导我减少角函数的代码,并请参阅所附的屏幕截图。代码末尾的结果是什么 $scope.Customer_profileMonth_data = function(data){ $scope.data: [ { "VisitTime": "08:36:23", "orgDwellTime": 27, "consumerID": 7245, "ConsumerAge": 46,

如果可能的话,减少代码行。我得到的结果很好。请指导我减少角函数的代码,并请参阅所附的屏幕截图。代码末尾的结果是什么

$scope.Customer_profileMonth_data = function(data){
$scope.data: [
    {
        "VisitTime": "08:36:23",
        "orgDwellTime": 27,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-11",
        "DAY": "Monday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "17:08:16",
        "orgDwellTime": 64,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-11",
        "DAY": "Monday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "21:29:51",
        "orgDwellTime": 2,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-11",
        "DAY": "Monday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "17:18:11",
        "orgDwellTime": 10,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-12",
        "DAY": "Tuesday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "20:16:48",
        "orgDwellTime": 39,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-13",
        "DAY": "Wednesday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "16:26:14",
        "orgDwellTime": 55,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-20",
        "DAY": "Wednesday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "12:51:42",
        "orgDwellTime": 22,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-21",
        "DAY": "Thursday",
        "ConsumerGender": "M"
    },
    {
        "VisitTime": "17:43:17",
        "orgDwellTime": 76,
        "consumerID": 7245,
        "ConsumerAge": 46,
        "VisitDate": "2016-01-27",
        "DAY": "Wednesday",
        "ConsumerGender": "M"
    }]
    var s ="count";
    var d ="orgDwellTime";
    var e ="orgDwellTimeavg";

    for(var i=1; i<=62; i++){
        //s = s+i
        //console.log(s+i);
        $scope[s+i] = 0;
        $scope[d+i] = 0;
        $scope[e+i] = 0;
        //console.log($scope[s])        
    }

    $scope.Monthgender_details = data;
    //$rootScope.footfallmonth= $scope.Monthgender_details;

    for(var i=0; i<$scope.Monthgender_details.length; i++){
        $scope.splitmonth =  $scope.Monthgender_details[i].VisitDate.split('-');
        $scope.customer_profile_gender = $scope.Monthgender_details[i].ConsumerGender;
    //console.log("footfall api calling pages ", $scope.yyyy);
            if($scope.splitmonth[2] == "01"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count1 ++;   
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count2 ++;
                }

            }else if($scope.splitmonth[2] == "02"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count3 ++;   
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count4 ++;
                }

            }else if($scope.splitmonth[2] == "03"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count5 ++;   
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count6 ++;
                }

            }else if($scope.splitmonth[2] == "04"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count7 ++;   
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count8 ++;
                }

            }else if($scope.splitmonth[2] == "05"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count9 ++;   
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count10 ++;
                }

            }else if($scope.splitmonth[2] == "06"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count11 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count12 ++;
                }


            }else if($scope.splitmonth[2] == "07"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count13 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count14 ++;
                }


            }else if($scope.splitmonth[2] == "08"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count15 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count16 ++;
                }


            }else if($scope.splitmonth[2] == "09"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count17 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count18 ++;
                }


            }else if($scope.splitmonth[2] == "10"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count19 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count20 ++;
                }


            }else if($scope.splitmonth[2] == "11"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count21 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count22 ++;
                }


            }else if($scope.splitmonth[2] == "12"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count23 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count24 ++;
                }

            }else if($scope.splitmonth[2] == "13"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count25 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count26 ++;
                }

            }else if($scope.splitmonth[2] == "14"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count27 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count28 ++;
                }
            }else if($scope.splitmonth[2] == "15"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count29 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count30 ++;
                }

            }else if($scope.splitmonth[2] == "16"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count31 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count32 ++;
                }

            }else if($scope.splitmonth[2] == "17"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count33 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count34 ++;
                }


            }else if($scope.splitmonth[2] == "18"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count35 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count36 ++;
                }


            }else if($scope.splitmonth[2] == "19"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count37 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count38 ++;
                }


            }else if($scope.splitmonth[2] == "20"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count39 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count40 ++;
                }


            }else if($scope.splitmonth[2] == "21"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count41 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count42 ++;
                }


            }else if($scope.splitmonth[2] == "22"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count43 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count44 ++;
                }


            }else if($scope.splitmonth[2] == "23"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count45 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count46 ++;
                }
            }else if($scope.splitmonth[2] == "24"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count47 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count48 ++;
                }


            }else if($scope.splitmonth[2] == "25"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count49 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count50 ++;
                }


            }else if($scope.splitmonth[2] == "26"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count51 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count52 ++;
                }


            }else if($scope.splitmonth[2] == "27"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count53 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count54 ++;
                }


            }else if($scope.splitmonth[2] == "28"){

                if($scope.customer_profile_gender =="M"){
                    $scope.count55 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count56 ++;
                }


            }else if($scope.splitmonth[2] == "29"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count57 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count58 ++;
                }

            }else if($scope.splitmonth[2] == "30"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count59 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count60 ++;
                }
            }else if($scope.splitmonth[2] == "31"){
                if($scope.customer_profile_gender =="M"){
                    $scope.count61 ++;  
                }else if($scope.customer_profile_gender =="F"){
                    $scope.count62 ++;
                }
            }
    }

    $scope.Customer_genderM =   [$scope.count1, $scope.count3, $scope.count5, $scope.count7, $scope.count9, $scope.count11, $scope.count13, $scope.count15, $scope.count17, $scope.count19, $scope.count21, $scope.count23, $scope.count25, $scope.count27, $scope.count29, $scope.count31, $scope.count33, $scope.count35, $scope.count37, $scope.count39, $scope.count41, $scope.count43, $scope.count45, $scope.count47, $scope.count49, $scope.count51, $scope.count53, $scope.count55, $scope.count57, $scope.count59, $scope.count61];
    $scope.Customer_genderF =   [$scope.count2, $scope.count4, $scope.count6, $scope.count8, $scope.count10, $scope.count12, $scope.count14, $scope.count16, $scope.count18, $scope.count20, $scope.count22, $scope.count24, $scope.count26, $scope.count28, $scope.count30, $scope.count32, $scope.count34, $scope.count36, $scope.count38, $scope.count40, $scope.count42, $scope.count44, $scope.count46, $scope.count48, $scope.count50, $scope.count52, $scope.count54, $scope.count56, $scope.count58, $scope.count60, $scope.count62];
//$scope.Customer_genderM = [22,34,21,35,10, 24, 20, 32, 18, 5,10, 24, 20, 32, 18, 5,10, 24, 20, 32, 18, 5,10, 24, 20, 32, 18, 5, 40, 54]
//$scope.Customer_genderF = [32, 18, 5,10, 24, 20, 32, 18, 5,10, 24, 20, 32, 18, 5, 40, 54, 0, 22,34,21,35,10, 24, 20,32, 18, 5,10, 24]
    $scope.users = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24','25', '26', '27', '28', '29', '30', '31'];
    console.log($scope.Customer_genderM);
    console.log($scope.Customer_genderF);
    console.log($scope.users);
    CustomerProfiling_gender($scope.Customer_genderM, $scope.Customer_genderF, $scope.users);

}
$.getScript("https://www.google.com/jsapi", function () {
google.load('visualization', '1.1' , 
{ 'callback': CustomerProfiling_gender,'packages': ['corechart'] });
});


 function CustomerProfiling_gender(genderM, genderF, month) {
//console.log("numberqqqq",genderM);
var Customer_genderM = genderM;
var Customer_genderF = genderF;
var Customer_gender_month = month;
var month = Customer_gender_month;
var male = Customer_genderM;
var female=Customer_genderF;
//console.log("numberqqqq",Customer_genderM);
    //console.log("numberqqqq",Customer_genderF);
var arr=[];
$scope.output=[];
var personId;
var personIndex;
for(var i=0;i<month.length;i++){
 personIndex = {
    "month": month[i],
     "genderM": male[i],
     "genderF": female[i],
//  ^ computed property name


};

 $scope.output.push(personIndex)



}
//console.log('output',$scope.output);




var customer = [Array('Month', 'Male', 'Female')]; 
$scope.output.forEach(function(value){

    customer.push([value.month, value.genderM, value.genderF]);
})

var data = google.visualization.arrayToDataTable(customer);
var options = {
    isStacked: 'percent',
    width: 510,
    height: 300,

    legend: { position: 'top', maxLines: 11 },
    bar: { groupWidth: '75%' },
    vAxis: { gridlines: { count: 12 } }
  };
  var chart = new google.visualization.ColumnChart(document.getElementById("barchart_values"));
  chart.draw(data, options);
  //console.log("Customer gender",data);
}
$scope.Customer\u profileMonth\u data=函数(数据){
$scope.data:[
{
“访问时间”:“08:36:23”,
“时间”:27,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-11”,
“日”:“星期一”,
“消费者”:“M”
},
{
“访问时间”:“17:08:16”,
“时间”:64,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-11”,
“日”:“星期一”,
“消费者”:“M”
},
{
“访问时间”:“21:29:51”,
“时间”:2,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-11”,
“日”:“星期一”,
“消费者”:“M”
},
{
“拜访时间”:“17:18:11”,
“时间”:10,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-12”,
“日”:“星期二”,
“消费者”:“M”
},
{
“访问时间”:“20:16:48”,
“时间”:39,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-13”,
“日”:“星期三”,
“消费者”:“M”
},
{
“访问时间”:“16:26:14”,
“时间”:55,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-20”,
“日”:“星期三”,
“消费者”:“M”
},
{
“访问时间”:“12:51:42”,
“时间”:22,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-21”,
“日”:“星期四”,
“消费者”:“M”
},
{
“访问时间”:“17:43:17”,
“时间”:76,
“consumerID”:7245,
“消费主义”:46,
“访问日期”:“2016-01-27”,
“日”:“星期三”,
“消费者”:“M”
}]
var s=“计数”;
var d=“时间”;
var e=“OrgDeliverTimeAvg”;
对于(var i=1;i类似的东西

var mydata = [
  [ "08:36:23", 27, 7245, 46, "2016-01-11", "Monday", "M" ], 
  [ "17:08:16", 64, 7245, 46, "2016-01-11", "Monday", "M" ], 
  [ "21:29:51", 2, 7245, 46, "2016-01-11", "Monday", "M" ], 
  [ "17:18:11", 10, 7245, 46, "2016-01-12", "Tuesday", "M" ], 
  [ "20:16:48", 39, 7245, 46, "2016-01-13", "Wednesday", "M" ], 
  [ "16:26:14", 55, 7245, 46, "2016-01-20", "Wednesday", "M" ], 
  [ "12:51:42", 22, 7245, 46, "2016-01-21", "Thursday", "M" ], 
  [ "17:43:17", 76, 7245, 46, "2016-01-27", "Wednesday", "M" ]
],
scopeData=[];
for (var i=0;i<mydata.length;i++) {
  scopeData.push({
    "VisitTime":      mydata[i][0],
    "orgDwellTime":   mydata[i][1],
    "consumerID":     mydata[i][2],
    "ConsumerAge":    mydata[i][3],
    "VisitDate":      mydata[i][4],
    "DAY":            mydata[i][5],
    "ConsumerGender": mydata[i][6]
  });
}
    $scope.Customer_profileMonth_data = function(data){
      $scope.data: scopeData;
    var s ="count";
    var d ="orgDwellTime";
    var e ="orgDwellTimeavg";

    for(var i=1; i<=62; i++){
      //s = s+i
      //console.log(s+i);
      $scope[s+i] = 0;
      $scope[d+i] = 0;
      $scope[e+i] = 0;
      //console.log($scope[s])    
    }
    $scope.users=[];
    $scope.Monthgender_details = data;
    //$rootScope.footfallmonth= $scope.Monthgender_details;

    for(var i=0; i<$scope.Monthgender_details.length; i++){
      $scope.splitmonth =  parseInt($scope.Monthgender_details[i].VisitDate.split('-'),10);
      $scope.customer_profile_gender = $scope.Monthgender_details[i].ConsumerGender;
    //console.log("footfall api calling pages ", $scope.yyyy);
      for (var i=0;i<30;i++) {
        $scope.users.push(""+(i+1));
        if($scope.customer_profile_gender =="M"){
          $scope["count"+($scope.splitmonth)]++;  
        }else if($scope.customer_profile_gender =="F"){
          $scope["count"+($scope.splitmonth+1)]++;  
        }
      }
    }
    for (var i=0;i<30;i+=2) { 
      $scope.Customer_genderM.push($scope["count"+i]);
      $scope.Customer_genderF.push($scope["count"+(i+1)]);
    }  
var mydata=[
[“08:36:23”,27,7245,46,“2016-01-11”,“星期一”,“M”],
[“17:08:16”,647245,46,“2016-01-11”,“星期一”,“M”],
[“21:29:51”,27245,46,“2016-01-11”,“星期一”,“M”],
[“17:18:11”,10724546,“2016-01-12”,“星期二”,“M”],
[“20:16:48”,397245,46,“2016-01-13”,“星期三”,“M”],
[“16:26:14”,557245,46,“2016-01-20”,“星期三”,“M”],
[“12:51:42”、22、7245、46、“2016-01-21”、“星期四”、“M”],
[“17:43:17”,767245,46,“2016-01-27”,“星期三”,“M”]
],
scopeData=[];
对于(var i=0;i类似的东西

var mydata = [
  [ "08:36:23", 27, 7245, 46, "2016-01-11", "Monday", "M" ], 
  [ "17:08:16", 64, 7245, 46, "2016-01-11", "Monday", "M" ], 
  [ "21:29:51", 2, 7245, 46, "2016-01-11", "Monday", "M" ], 
  [ "17:18:11", 10, 7245, 46, "2016-01-12", "Tuesday", "M" ], 
  [ "20:16:48", 39, 7245, 46, "2016-01-13", "Wednesday", "M" ], 
  [ "16:26:14", 55, 7245, 46, "2016-01-20", "Wednesday", "M" ], 
  [ "12:51:42", 22, 7245, 46, "2016-01-21", "Thursday", "M" ], 
  [ "17:43:17", 76, 7245, 46, "2016-01-27", "Wednesday", "M" ]
],
scopeData=[];
for (var i=0;i<mydata.length;i++) {
  scopeData.push({
    "VisitTime":      mydata[i][0],
    "orgDwellTime":   mydata[i][1],
    "consumerID":     mydata[i][2],
    "ConsumerAge":    mydata[i][3],
    "VisitDate":      mydata[i][4],
    "DAY":            mydata[i][5],
    "ConsumerGender": mydata[i][6]
  });
}
    $scope.Customer_profileMonth_data = function(data){
      $scope.data: scopeData;
    var s ="count";
    var d ="orgDwellTime";
    var e ="orgDwellTimeavg";

    for(var i=1; i<=62; i++){
      //s = s+i
      //console.log(s+i);
      $scope[s+i] = 0;
      $scope[d+i] = 0;
      $scope[e+i] = 0;
      //console.log($scope[s])    
    }
    $scope.users=[];
    $scope.Monthgender_details = data;
    //$rootScope.footfallmonth= $scope.Monthgender_details;

    for(var i=0; i<$scope.Monthgender_details.length; i++){
      $scope.splitmonth =  parseInt($scope.Monthgender_details[i].VisitDate.split('-'),10);
      $scope.customer_profile_gender = $scope.Monthgender_details[i].ConsumerGender;
    //console.log("footfall api calling pages ", $scope.yyyy);
      for (var i=0;i<30;i++) {
        $scope.users.push(""+(i+1));
        if($scope.customer_profile_gender =="M"){
          $scope["count"+($scope.splitmonth)]++;  
        }else if($scope.customer_profile_gender =="F"){
          $scope["count"+($scope.splitmonth+1)]++;  
        }
      }
    }
    for (var i=0;i<30;i+=2) { 
      $scope.Customer_genderM.push($scope["count"+i]);
      $scope.Customer_genderF.push($scope["count"+(i+1)]);
    }  
var mydata=[
[“08:36:23”,27,7245,46,“2016-01-11”,“星期一”,“M”],
[“17:08:16”,647245,46,“2016-01-11”,“星期一”,“M”],
[“21:29:51”,27245,46,“2016-01-11”,“星期一”,“M”],
[“17:18:11”,10724546,“2016-01-12”,“星期二”,“M”],
[“20:16:48”,397245,46,“2016-01-13”,“星期三”,“M”],
[“16:26:14”,557245,46,“2016-01-20”,“星期三”,“M”],
[“12:51:42”、22、7245、46、“2016-01-21”、“星期四”、“M”],
[“17:43:17”,767245,46,“2016-01-27”,“星期三”,“M”]
],
scopeData=[];

对于(var i=0;isounds more a question听起来更像一个问题感谢您的快速重播,但没有得到预期的答案,所有数组都是“0”。男性和女性计数都是正确的,但仍然是结果(Customer_genderM=[未定义,0,0,0,0,0,0,0,0,0,0]和Customer_genderF=[0,0,0,0,0,0,0,0,0,0,0,0,0,0])是错误的。由您来修复错误。我没有您的其余代码来测试我的代码。添加一些console.log以查看我是否输入错误感谢快速重播,但没有得到预期的答案,所有数组都是“0”。男女计数都是正确的,但结果仍然是正确的(Customer\u genderM=[undefined,0,0,0,0,0,0,0,0,0,0,0,0]和Customer_genderF=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]是错误的。这取决于您对其进行错误修复。我没有其他代码来测试我的代码。添加一些console.log以查看我是否输入了错误