ASP图表标签显示在多个系列ASP.NET 4的数据点上

时间:2011-03-09 15:58:01

标签: asp.net vb.net asp.net-charts

我有一个ASP图表(v4),它可以完美地显示我需要的数据。我希望它在数据点的顶部显示标签,我遇到了一些困难。

这是我的代码,适用于两个系列,但不显示标签:

If MySQLReader.HasRows Then
            Chart1.DataSource = MySQLReader
            Chart1.Series("New Customers Created").XValueMember = "Salesperson"
            Chart1.Series("New Customers Created").YValueMembers = "NCC"
            Chart1.Series("Target").XValueMember = "Salesperson"
            Chart1.Series("Target").YValueMembers = "Target"
            Chart1.DataBind()

            Chart1.Height = 500
            Chart1.Width = 750
            Chart1.ChartAreas("ChartArea1").AxisX.MajorGrid.Enabled = False
            Chart1.ChartAreas("ChartArea1").AxisY.MajorGrid.Enabled = True

            LBLError.Text = ""
        Else
            Chart1.Visible = False
            LBLError.Text = "<div class='error'>Your search did not match any records in the database. Please try again</div>"
        End If
        MySQLReader.Close()
        MyConn.Close()

现在,这是我更新的代码,显示标签但仅适用于一个系列。

If MySQLReader.HasRows Then

            Chart1.Series("New Customers Created").Points.DataBind(MySQLReader, "Salesperson", "NCC", "Label=NCC")
            Chart1.Series("Target").Points.DataBind(MySQLReader, "Salesperson", "Target", "Label=Target")
            Chart1.Height = 500
            Chart1.Width = 750
            Chart1.ChartAreas("ChartArea1").AxisX.MajorGrid.Enabled = False
            Chart1.ChartAreas("ChartArea1").AxisY.MajorGrid.Enabled = True

            Chart1.Series("New Customers Created")("LabelStyle") = "Bottom"
            Chart1.Series("New Customers Created").Font = New Drawing.Font("Arial", 8)
            LBLError.Text = ""
        Else
            Chart1.Visible = False
            LBLError.Text = "<div class='error'>Your search did not match any records in the database. Please try again</div>"
        End If
        MySQLReader.Close()
        MyConn.Close()

所以我的问题是,请您帮助我在更新的代码中显示两个系列,并为每个系列添加标签?谢谢!

1 个答案:

答案 0 :(得分:1)

好的,我明白了。

使用第一批代码很好。添加以下IsValueShownAsLabel="True“会显示标签:

<asp:Series Name="New Customers Created" Legend="New Cust" IsValueShownAsLabel="True">
                    </asp:Series>
                    <asp:Series Name="Target" Legend="New Cust" IsValueShownAsLabel="True">
                    </asp:Series>