C# 将图表类型绑定到按钮单击

C# 将图表类型绑定到按钮单击,c#,html,C#,Html,我正在尝试将图形的图表类型绑定到VisualStudio中的按钮单击事件。因此,当单击相应的按钮时,图表将更改为指示的类型;但是,到目前为止,它什么也没做。到目前为止,我对这个问题的回答如下: public partial class WebForm2 : System.Web.UI.Page { String ddlValueX, ddlValueY; enum SeriesChartType { Pie,

我正在尝试将图形的图表类型绑定到VisualStudio中的按钮单击事件。因此,当单击相应的按钮时,图表将更改为指示的类型;但是,到目前为止,它什么也没做。到目前为止,我对这个问题的回答如下:

public partial class WebForm2 : System.Web.UI.Page
    {
        String ddlValueX, ddlValueY;
        enum SeriesChartType
        {
            Pie,
            Bar,
            Graph
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Manually regiseter the event-handling method for the click event
            btnPie.Click += new EventHandler(this.btnPie_Click);
            btnBar.Click += new EventHandler(this.btnBar_Click);
            btnGraph.Click += new EventHandler(this.btnGraph_Click);
        }

        public void btnPie_Click(object sender, EventArgs e)
        {
            this.Chart1.Series["Series1"].ChartType = (System.Web.UI.DataVisualization.Charting.SeriesChartType)(SeriesChartType.Pie);
            Chart1.DataBind();
        }

        public void btnBar_Click(object sender, EventArgs e)
        {
            this.Chart1.Series["Series1"].ChartType = (System.Web.UI.DataVisualization.Charting.SeriesChartType)(SeriesChartType.Bar);
            Chart1.DataBind();
        }

        public void btnGraph_Click(object sender, EventArgs e)
        {
            this.Chart1.Series["Series1"].ChartType = (System.Web.UI.DataVisualization.Charting.SeriesChartType)(SeriesChartType.Graph);
            Chart1.DataBind();
        }
我希望这会将图表绑定到buttonClick上指定的类型,但它似乎对页面没有影响。我遇到了一个不兼容的类型错误,直到我尝试这样强制转换:

(System.Web.UI.DataVisualization.Charting.SeriesChartType)(SeriesChartType.Graph);
老实说,我不相信这是正确的,但我不知道还能做什么

受影响部分的HTML如下所示:

    <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="server">
    <div>
        <div id="Main" style="height: 100%; width: 100%">
            <div id="Profile" style="height: 100%; width: 18%; float: left;">
                <div id="profilePicture" style="padding-bottom: 10%;">
                    <img alt="" src="profile_picture_by_ralucs_stock-d6jc4xg.jpg" style="width: 80%;" />
                </div>
                <div id="profileInfo" style="padding-bottom: 10%;">
                    <h5>Username</h5>
                    <h5>Interests</h5>
                </div>
                <div id="messageBox">
                    <h5>TBA</h5>
                </div>
            </div>
            <div id="Body" style="height: 100%; width:80%; float: right;">
                <div id="button">
                    <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:Button ID="btnPie" OnClick="btnPie_Click" runat="server" Text="Pie" />
                            <asp:Button ID="btnBar" OnClick="btnBar_Click" runat="server" Text="Bar" />
                            <asp:Button ID="btnGraph" OnClick="btnGraph_Click" runat="server" Text="Graph" />
                            <br />
                            <asp:DropDownList ID="ddlUserInfo1"  runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlUserInfo1_SelectedIndexChanged">
                                <asp:ListItem Text="Please Make a Selection" Value="0" />
                                <asp:ListItem Value="1">Gender</asp:ListItem>
                                <asp:ListItem Value="2">Location</asp:ListItem>
                                <asp:ListItem Value="3">Guild</asp:ListItem>
                                <asp:ListItem Value="4">Material</asp:ListItem>
                                <asp:ListItem Value="5">Type</asp:ListItem>
                                <asp:ListItem Value="6">Quantity</asp:ListItem>
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlUserInfo2" runat="server" AutoPostBack="True">
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlUserInfo3" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlUserInfo3_SelectedIndexChanged">
                                <asp:ListItem Text="Please Make a Selection" Value="0" />
                                <asp:ListItem Value="1">Age Bracket</asp:ListItem>
                                <asp:ListItem Value="2">Product Cost</asp:ListItem>
                                <asp:ListItem Value="3">Quantity Sold</asp:ListItem>
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlUserInfo4" runat="server" AutoPostBack="True">
                            </asp:DropDownList>
                        </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ddlUserInfo1" EventName="SelectedIndexChanged" />
                    </Triggers>
                    </asp:UpdatePanel>
                </div>
                <div id="chart">
                    <asp:Chart ID="Chart1" runat="server" Width="569px" DataSourceID="Database1">
                        <Series>
                            <asp:Series Name="Series1" XValueMember="GuildTypeName" YValueMembers="ProductCost">
                            </asp:Series>
                        </Series>
                        <ChartAreas>
                            <asp:ChartArea Name="ChartArea1">
                            </asp:ChartArea>
                        </ChartAreas>
                    </asp:Chart>
                    <asp:SqlDataSource ID="Database1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Stats]"></asp:SqlDataSource>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

用户名
兴趣
TBA

性别 地方 公会 布料 类型 量 年龄段 产品成本 销售量

我对C#和HTML都是新手,因此非常感谢您的帮助。

我敢打赌,问题是您创建了自己的
SeriesChartType
enum,而不仅仅是使用
System.Web.UI.DataVisualization.Charting.SeriesChartType
。只需使用System.Web.UI.DataVisualization.Charting添加行
在类定义上方,删除自定义枚举,无需强制转换类型。此外,无需指定两次单击处理程序。您可以完全删除
PageLoad
处理程序,只需依赖ASP文件中的
OnClick
属性即可。要删除枚举,请删除pageu\load中的处理程序。您可以像这样
this.Chart1.Series[“Series1”].ChartType=SeriesChartType.Pie谢谢你的帮助!我做了更改,但当我单击按钮时,它仍然没有更新。我想这可能与回邮有关。我如何投票?