0

我试图在特定区域显示我的融合图表,特别是在单击按钮时我在我的 aspx 文件中调用 CreateChart 函数的地方。我现在拥有的方式是图表在页面加载后立即加载,但我想看到的是图表仅在单击按钮时加载。我尝试了不同的方法,但由于我对融合图表不太熟悉,因此无法做到正确。谢谢 这是我的 ASPX 文件:

<table class="style1">

<td class="style8">
                <asp:Button ID="btnClick" runat="server" Height="29px" Text="Button" 
                    Width="158px" onclick="btnClick_Click" />
            </td>

 <td class="style4" colspan="2">
               <% =CreateChart() %> </td>
        </tr>
    </table>

这是我的代码:

public string CreateChart()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
        string sqlStatement = "select   Status1, Count(Status1) as TotalCount from  MyTable where Closing_Date =  '" + txtStartClosingDate.Text + "' and Closing_Date <= '" + txtEndClosingDate.Text + "' and Status1 is not null group by  Status1";
        SqlCommand cmd = new SqlCommand(sqlStatement, con);
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        string strXML;
        strXML = "<graph labelDisplay='auto' useEllipsesWhenOverflow='1' decimals='2' 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/Pie2D.swf", "ChartID", strXML, "FactorySum", "450", "450", false, false);

    }
4

1 回答 1

1

试试这个

代替

<td class="style4" colspan="2">
           <% =CreateChart() %> </td>

采用

<td class="style4" colspan="2">
           <asp:Literal mode="PassThrough" runat="server" ID="literalPlaceHolder"/> </td>

并在按钮的事件处理程序中

public void btnClick_Click(...)
{
       literalPlaceHolder.Text = CreateChart();
}
于 2013-01-22T21:07:22.557 回答