我有一个从数据表中获取值的饼图。
这是我的代码:
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
问题是当我运行代码时,饼图没有显示。
有人可以告诉我有什么问题吗?