未显示可视化图表

Visualization chart not being displayed

本文关键字:可视化 显示      更新时间:2023-09-26

我有下面的代码。我试图创建谷歌可视化柱图与每个条包含多个数据点。但是没有显示可视化图表。我得到错误,如ReferenceError: convertToISO未定义是错误。请帮帮我。

<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>   

问题是,在下一行代码中,而不是SQL查询的一部分,您试图将convertToISO(dateMax)作为javascript函数调用运行。你没有定义任何这样的函数所以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 ";