Chart control. I need to add a Custom Label that I can place at a given position on or near each series.

Alvord, Timothy 276 Reputation points
2024-11-14T18:08:12.9466667+00:00

Chart control. Custom Labels

(1) I need to add a Custom Label that I can place at a given position on or near each series.

(2) I need to add a Custom label (or Legend) that I can place at a given position on the chart or Chart Area.

Desired:

(1) The example below shown as Goal XX

(2) The Legend or Label on the right that shows:

Red < 50%, Yellow < 75%,

Green 100%, Blue > 100%

User's image

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,091 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 47,501 Reputation points Microsoft Vendor
    2024-11-15T03:02:17.8466667+00:00

    Hi @Alvord, Timothy, Welcome to Microsoft Q&A,

    You can easily add a legend to your chart. But you need to customize the text you need. You need to write a function for the text you need to appear, and then assign it.

    // Add a new legend
    
    Legend customLegend = new Legend("CustomLegend");
    
    chart1.Legends.Add(customLegend);
    
    // Create a custom legend item
    
    LegendItem legendItem = new LegendItem();
    
    legendItem.Name = "CustomLabel";
    
    legendItem.Color = Color.Red; // Set the color
    
    legendItem.BorderColor = Color.Black;
    
    legendItem.BorderWidth = 1;
    
    legendItem.MarkerStyle = MarkerStyle.Circle;
    
    legendItem.MarkerSize = 10;
    
    legendItem.MarkerColor = Color.Red;
    
    legendItem.Cells.Add(LegendCellType.Text, "xxxx", ContentAlignment.MiddleLeft);
    
    // Add the legend item to the legend
    
    customLegend.CustomItems.Add(legendItem);
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.