Set Series Item Name - Legend

Thread is closed for posting
2 posts, 1 answers
  1. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 16 Jun 2011 Link to this post

    I have a chart that is almost generating like I'd like it to. The only thing that is missing is the Labels for the Legend. I currently have the Legend set to display ItemLabels. I thought I set the item labels when I added the item, but apparently not. How do I go about setting these ItemLabels? Below is the code I'm using to build the Chart, and attached is an image of what the chart currently looks like.

    reader.GetValue(2) will pull the label text from the database.

    protected void makechart()
                RadChart invChart = new RadChart();
                invChart.ChartTitle.Visible = false;
                // Create a ChartSeries and assign its name and chart type
                ChartSeries chartSeries = new ChartSeries();
                chartSeries.Name = "TotalValue";
                chartSeries.Type = ChartSeriesType.Pie;
                // Display Item Labels in the Legend
                chartSeries.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
                // Open SQL Connection
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                SqlCommand command = new SqlCommand("GetInventoryValue", connection);
                command.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                    // Set value and value text
                    chartSeries.AddItem((Double)(reader.GetValue(0)), reader.GetValue(0).ToString());
                // Close SQL Connection
                // add the series to the RadChart Series collection
                // add the RadChart to the page.
  2. Answer
    HrMeibom avatar
    2 posts
    Member since:
    Feb 2004

    Posted 20 Jun 2011 Link to this post

    Hi William,

    I believe you'll need to set the name of the series item for each item you add. Something like:



    while (reader.Read()) 
        // Set value and value text 
        ChartSeriesItem chartSeriesItem = new ChartSeriesItem((double)reader.GetValue(0), reader.GetValue(0).ToString()); 
        chartSeriesItem.Name = reader.GetValue(2).ToString()

    I hope this does the trick... I do have legends on my Pie chart.
    And thanks, you solved my problem with the LegendDisplayMode property :-)

    Best regards
Back to Top