ASP Chart Labels to display at the data points on multiple series ASP.NET 4

James picture James · Mar 9, 2011 · Viewed 7k times · Source

I have an ASP Chart (v4) which displays the data I need perfectly. I want it to show labels at the top of the data points and I am having some difficulty with it.

Here is my code that works for both series but does not display the labels:

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()

Now here is my updated code that displays the Labels but only for one series.

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()

So my question is, please can you help me display both series in the updated code with labels for each series? Thanks!

Answer

James picture James · Mar 9, 2011

OK, I figured it out.

using the first batch of code is fine. Adding the following IsValueShownAsLabel="True" shows the labels:

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