ASP.NET饼图未显示

时间:2013-04-17 00:02:52

标签: asp.net vb.net datatable pie-chart

我有一个饼图,它从数据表中获取值。

这是我的代码:

ASP.NET代码:

<asp:Chart ID="Chart1" runat="server" EnableViewState="True">
                            <Series>
                                <asp:Series ChartType="Pie" Legend="% Completed" Name="Series1" XAxisType="Secondary" XValueType="Double" YValueType="Double">
                                </asp:Series>
                            </Series>
                            <ChartAreas>
                                <asp:ChartArea BorderWidth="5" Name="ChartArea1">
                                    <Area3DStyle Enable3D="True" WallWidth="15" />
                                </asp:ChartArea>
                            </ChartAreas>
                            <Legends>
                                <asp:Legend Name="% Completed" Title="% Completed">
                                </asp:Legend>
                            </Legends>
                            <Titles>
                                <asp:Title Name="Completed" Text="Completed">
                                </asp:Title>
                                <asp:Title Name="Title1">
                                </asp:Title>
                            </Titles>
                        </asp:Chart>

VB.NET代码:

GetTable()

设置会话变量
 Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load, Chart1.Load



        Dim ProjectID As Integer = Session("project_id")
        Session("ProjectID") = ProjectID

        lblProjNameHeading.Text = "[ " + ProjectID.ToString + " ]"

        Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True")
        Dim projComm As String = "SELECT project_id, project_start, project_finish, project_budget, project_cost FROM projects WHERE project_id=@parameter"


        Dim projSQL As New SqlCommand


        conn.Open()

        projSQL = New SqlCommand(projComm, conn)
        projSQL.Parameters.AddWithValue("@parameter", ProjectID.ToString)

        Dim datareader As SqlDataReader = projSQL.ExecuteReader()


        While datareader.Read

            lblProjectCode.Text = datareader("project_id").ToString
            lblProjectStart.Text = datareader("project_start").ToString
            lblProjectStart2.Text = datareader("project_start").ToString
            lblProjectEnd.Text = datareader("project_finish").ToString
            lblProjectEnd2.Text = datareader("project_finish").ToString
            lblProjectBudget.Text = datareader("project_budget").ToString
            lblProjectBudget2.Text = datareader("project_budget").ToString
            lblProjectCost.Text = datareader("project_cost").ToString
            lblProjectCost2.Text = datareader("project_cost").ToString
            ' lblProjectLeader.Text = datareader("project_cost").ToString
            'lblProjectExpenditures.Text = agdgssag

            Dim StartDate As DateTime = datareader("project_start")

            Dim FinishDate As DateTime = datareader("project_finish")

            Dim today As DateTime = DateTime.Now

            Dim sumDays = (FinishDate - StartDate).TotalDays
            Dim daysToNow = (today - StartDate).TotalDays

            Dim percentage = daysToNow / sumDays * 100

            Dim percentageLeft = 100 - percentage

            Session("PercentageCompleted") = percentage
            Session("PercentageLeft") = percentageLeft

            GetTable()


            lblProjectPercentage.Text = percentage.ToString("N2") + "%"







        End While


        datareader.Close()
        conn.Close()



        If Not Page.IsPostBack Then
            BindData()
        End If


    End Sub

问题在于,当我运行代码时,不会显示饼图。

有人可以告诉我出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

我认为问题是您没有为图表设置XvalueMember和YvalueMember。

<Series>
<asp:Series ChartType="Pie" Legend="% Completed" Name="Series1" XAxisType="Secondary" XValueType="Double" YValueType="Double" XValueMember="yourXValue" YValueMember="YourYvalue">
</asp:Series>
</Series>

查看以下示例。

http://itzonesl.blogspot.com/search/label/Charts