0

我有下面的代码。我正在尝试创建每个栏包含多个数据点的 google 可视化柱形图。但是没有显示可视化图表。我收到类似ReferenceError: convertToISO is not defined的错误是错误。请帮我。

<script type="text/javascript" src="http://google.com/jsapi"></script>    
<script src="/soap/ajax/19.0/connection.js" type="text/javascript" />  
<script type="text/javascript">      
formatCurrencyLabel = function( value )    
{  
    return "$" +     String(value); 
}
google.load("visualization" , "1" , {package:["ColumnChart"]});
google.setOnLoadCallback(Chart); 

function Chart() 
{
     data.addColumn(‘string’, ‘Timeframe’);        
     data.addColumn(‘number’, ‘Gold’);   
     data.addColumn(‘number’, ‘Platinum’); 
     data.addColumn(‘number’, ‘Millinium’);                         
     sforce.connection.sessionId = ‘{!$Api.Session_ID}’;  
     var date = new Date();
     var dateMin = date.setMonth(date.getMonth() -13);                  
     var  date = new Date();                  
     var dateMax = date.setMonth(date.getMonth() +1);                 
     var soql = "Select id,name,GOLD_Policies_InForce__c, MNS_Policies_InForce__c, 
         PLAT_Policies_InForce__c, Producer_Name__c, Type__c, Producer_Code__c  from
         Analytics__c where Producer_Name__c ='TestABC2' and Period__c ='21' and CreatedDate <"
       + convertToISO(dateMax) + " and convertToISO(CreatedDate) > " + dateMin + " Order by   
        CreatedDate asc ";                  //console.log(soql);         

  result = sforce.connection.query(soql);                
  var it = new sforce.QueryResultIterator(result);        
      while(it.hasNext())
  {                 
   var record = it.next();   
           data.addRow(['record.CreatedDate',
   {v:parseFloat(record.PLAT_Policies_InForce__c), f:
  formatCurrencyLabel(record.PLAT_Policies_InForce__c)},    
 {v:parseFloat(record.PLAT_Policies_InForce__c), f: 
 formatCurrencyLabel(record.PLAT_Policies_InForce__c)},         
 {v:parseFloat(record.GOLD_Policies_InForce__c), f:
 formatCurrencyLabel(record.GOLD_Policies_InForce__c)}         ]);                                    
  }   
  var options = {'title':'Policies Inforce Rolling 13 Months' , legend: 'left' ,                         
 'width':560,                       'height':228,                       'colors' :  
   ['green','orange','#B5C5D7']                  
 }; 
    var chart = new google.visualization.ColumnChart(document.getElementById('chart'));
     chart.draw(data , options);  
};    
</script>       
  <body><div id="chart"></div></body>   
4

1 回答 1

0

问题在于,在以下代码行中,您尝试convertToISO(dateMax)作为 javascript 函数调用运行,而不是 SQL 查询的一部分。您尚未定义任何此类函数,因此 JavaScript 引擎抱怨您正在尝试运行未定义的函数

var soql = "Select id,name,GOLD_Policies_InForce__c, MNS_Policies_InForce__c, 
     PLAT_Policies_InForce__c, Producer_Name__c, Type__c, Producer_Code__c  from
     Analytics__c where Producer_Name__c ='TestABC2' and Period__c ='21' and CreatedDate <"
   + convertToISO(dateMax) + " and convertToISO(CreatedDate) > " + dateMin + " Order by   
    CreatedDate asc ";

应该:

var soql = "Select id,name,GOLD_Policies_InForce__c, MNS_Policies_InForce__c, 
     PLAT_Policies_InForce__c, Producer_Name__c, Type__c, Producer_Code__c  from
     Analytics__c where Producer_Name__c ='TestABC2' and Period__c ='21' and CreatedDate < 
     convertToISO(" + dateMax + ") and convertToISO(CreatedDate) > " + dateMin + " Order by       
     CreatedDate asc ";
于 2013-04-01T13:48:57.187 回答