如何在asp中使用融合图显示饼图的总和

时间:2012-12-28 17:36:36

标签: asp.net fusioncharts

有没有办法用融合图表显示饼图的总和?我在ASP中创建了融合图表,我想要做的就是显示饼图所有切片的总和值。例如,如果我的饼图上有3个切片:每个切片都有这些值:20,30,25;所以我想在子标题区域或图表顶部显示总数75。有没有办法做到这一点?请帮忙。

 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='Average Days To Close' subcaption='I want to show here the Total Sum' labelDisplay='auto' useEllipsesWhenOverflow='1'  decimalPrecision='0' showValues='1' enablesmartlabels='0' showlabels='0'  legendAllowDrag='1' numberSuffix=' Days' showLegend='1' pieSliceDepth='45' 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", "450", "450", false, false);

    }

1 个答案:

答案 0 :(得分:0)

   SqlDataReader reader = cmd.ExecuteReader();
    string strXML;
    int sumAvgNumbers;
    string strXMLTemp;
while (reader.Read())
    {
        strXMLTemp += "<set name='" + reader["Category"].ToString() + "' value='" + reader["AvgNumbers"].ToString() + "' />";
        sumAvgNumbers = sumAvgNumbers + Convert.toInt32(reader["AvgNumbers"].ToString());
    }
    strXML = "<graph caption='Average Days To Close' subcaption='"+ sumAvgNumbers +"' labelDisplay='auto' useEllipsesWhenOverflow='1'  decimalPrecision='0' showValues='1' enablesmartlabels='0' showlabels='0'  legendAllowDrag='1' numberSuffix=' Days' showLegend='1' pieSliceDepth='45' formatNumberScale='0'>";
    strXML += strXMLTemp;