我有以下代码。我正在尝试创建google visualcolumn图表,每个栏包含多个数据点。但可视化图表未显示。我收到错误,如 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 :(得分: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 ";