JavaScript代码并不总是有效

时间:2015-07-06 14:25:37

标签: javascript c# asp.net fusioncharts

我正在使用Fusionchart XT,它应该生成一个生成图表的javaScript。

这是第一个正在运行的脚本:

    <!-- Using ASP.NET FusionCharts Wrapper and JavaScript rendering --><!-- START Script Block for Chart Kund_Sprache -->
<div id='Kund_Sprache_div' >
Chart...
</div>
<script type="text/javascript">
FusionCharts && FusionCharts.ready(function () {
if (FusionCharts("Kund_Sprache") ) FusionCharts("Kund_Sprache").dispose();
var chart_Kund_Sprache = new FusionCharts({
"width" : "50%", 
"height" : "100%      ", 
"id" : "Kund_Sprache", 
"type" : "Pie2D", 
"dataSource" : "<chart logoURL='coins.png' caption='Sprache' showvalues='1' showlabels='0' showlegend='1' legendborder='0' legendposition='right' theme='flat'><set label='DE' value='239'/><set label='FR' value='50'/><set label='IT' value='60'/><set label='EN' value=70'/></chart>", 
"dataFormat" : "xml", 
"renderAt" : "Kund_Sprache_div", 
}).render();
});
</script>
<!-- END Script Block for Chart Kund_Sprache -->

然后我得到了第二个,它不起作用,只显示“Chart ...”:

    <!-- Using ASP.NET FusionCharts Wrapper and JavaScript rendering --><!-- START Script Block for Chart Kund -->
<div id='Kund_div' >
Chart...
</div>
<script type="text/javascript">
FusionCharts && FusionCharts.ready(function () {
if (FusionCharts("Kund") ) FusionCharts("Kund").dispose();
var chart_Kund = new FusionCharts({
"width" : "50%", 
"height" : "100%", 
"id" : "Kund", 
"type" : "Pie2D", 
"dataSource" : "<chart showvalues='1' caption='Kund' showlabels='0' showlegend='1' legendborder='0' legendposition='right' theme='flat'><set label='1 St' value='26'/><set label='2 St' value='41'/><set label='3 St' value='9'/></chart>", 
"dataFormat" : "xml", 
"renderAt" : "Kund_div", 
}).render();
});
</script>
<!-- END Script Block for Chart Kund -->

有没有人看到差异?或者为什么javascript没有在第二个执行? (它只显示第一个div)

1 个答案:

答案 0 :(得分:1)

我忘了在头标记内链接FusionChart脚本:

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
     <script src="/Fusioncharts/fusioncharts.js"></script>
    <script src="/Fusioncharts/themes/fusioncharts.theme.flat.js"></script>
</asp:Content>