将ChartType绑定到按钮单击

时间:2015-04-03 11:26:29

标签: c# html

我试图将图表的chartType绑定到Visual Studio中的按钮单击事件。因此,当单击相应的按钮时,图表将更改为指示的类型;但是,到目前为止,它还没有做任何事情。到目前为止,我的C#问题看起来像这样:

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>

我对C#和HTML都很陌生,所以我们非常感谢任何帮助。

0 个答案:

没有答案