2013-03-29 33 views
0

我有下面的代码。我想创建谷歌可视化列图表,每个酒吧包含多个数据点。但没有显示可视化图表。我得到像错误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> 

回答

0

的问题是,在下面的行,而不是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 "; 
+0

仍然没有被显示的图表。我也对你的查询做了一些改变,我得到错误。 var date = new Date();可变日期重新声明参数。请帮助我。 –