我在一页中有多个图表,但是在运行它时出现此错误:
Chart Id is same as a JavaScript variable name. Variable naming error. Please use unique name for chart JS variable, chart-id and container id.
如果我只保留一张图表,那就很高兴了。我怎样才能解决这个问题?这是我的代码:
public string CreateChart()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
string sqlStatement = "SELECT Category, AvgNumbers FROM MyTable";
SqlCommand cmd = new SqlCommand(sqlStatement, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
string strXML;
strXML = "<graph caption='Summary' subCaption='By Category' decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='30' formatNumberScale='0'>";
while (reader.Read())
{
strXML += "<set name='" + reader["Category"].ToString() + "' value='" + reader["AvgNumbers"].ToString() + "' />";
}
strXML += "</graph>";
return FusionCharts.RenderChart("/FusionCharts/Pie3D.swf", "ChartID", strXML, "FactorySum", "650", "450", false, false);
}
protected string CreateChart_2()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
string sqlStatement = "SELECT count (ID)as ID, cat_name FROM MainTable group by cat_name";
SqlCommand cmd = new SqlCommand(sqlStatement, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
string strXML1;
strXML1 = "<graph caption='Summary' subCaption='By Cat' decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='30' formatNumberScale='0'>";
while (reader.Read())
{
strXML1 += "<set name='" + reader["cat_name"].ToString() + "' value='" + reader["ID"].ToString() + "' />";
}
strXML1 += "</graph>";
return FusionCharts.RenderChart("/FusionCharts/Pie3D.swf", "MyChartID", strXML1, "FactorySum", "650", "450", false, false);
}
ASP 代码:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div>
<% =CreateChart() %>
</div>
<div>
<% =CreateChart_2() %>
</div>
</asp:Content>
我已经尝试了所有方法,但到目前为止还没有找到解决方案。