估计可能出现的问题就是中文的编码问题了。
<div id="chartdiv"></div>
<script>
var myChart = new FusionCharts("../Scripts/MSLine.swf", "myChartId", "800", "300");
myChart.setDataURL("<%=Url.Action("Xml","Home") %>");
myChart.render("chartdiv");
</script>
在页面中添加这样的几句,记得之前需要引入的js
然后在Home/Xml中写如下操作
public void Xml()
{
StringBuilder str = new StringBuilder();
str.Append("<chart caption='XXXXXX统计' subcaption='(从 8/6/2009 to 8/12/2009)' lineThickness='1' showValues='0' formatNumberScale='0' anchorRadius='2' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='1' numvdivlines='5' chartRightMargin='35' bgColor='FFFFFF,CC3300' bgAngle='270' bgAlpha='10,10' xAxisName='月份' yAxisName='销售额' rotateYAxisName='0' baseFont='Arial' baseFontSize='13'>");
str.Append("<categories>");
str.Append("<category label='8/6/2006' />");
str.Append("<category label='8/7/2006' />");
str.Append("<category label='8/8/2006' />");
str.Append("<category label='8/9/2006' />");
str.Append("<category label='8/10/2006' />");
str.Append("<category label='8/11/2006' />");
str.Append("<category label='8/12/2006' />");
str.Append("</categories>");
str.Append("<dataset seriesName='测试1' color='1D8BD1' anchorBorderColor='1D8BD1' anchorBgColor='1D8BD1'>");
str.Append("<set value='1327' />");
str.Append("<set value='1826' />");
str.Append("<set value='1699' />");
str.Append("<set value='1511' />");
str.Append("<set value='1904' />");
str.Append("<set value='1957' />");
str.Append("<set value='1296' />");
str.Append("</dataset>");
str.Append("</chart>");
String str1 = str.ToString();
/*Encoding Default = Encoding.Default;
Encoding GB2312 = Encoding.GetEncoding("GBK");
byte[] temp = Default.GetBytes(str1);
String res = GB2312.GetString(temp);*/
//ViewData["list"] = res;
/*String path = Server.MapPath("~/");
if (!System.IO.File.Exists(path + "data.xml")) {
System.IO.File.Create(path + "data.xml");
}
StreamWriter sw = new StreamWriter(path + "data.xml", false,GB2312);
sw.Write(res);
sw.Close();*/
Response.Clear();
Response.ClearHeaders();
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.Write(str1);
Response.Flush();
Response.End();
}
之前一直是乱码,原来动态生成的数据需要是GB2312编码的。
发送个头编码就OK了。
这里有全部FusionCharts的静态例子,非常好用,从网上找到的。
共享出来,这样大家需要调什么样式非常方便。Demo