This is a migrated thread and some comments may be shown as answers.

Location of the label at the center and above the point in Line Chart.

1 Answer 28 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Yaroslav
Top achievements
Rank 1
Yaroslav asked on 26 Jan 2012, 12:18 PM
How to place the label of Line chart top and center relative to the point?

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 31 Jan 2012, 11:44 AM
Hello,

Presently, there is no way to achieve this with out-of-the-box means.

However, I can suggest a work-around for this. In a resume you will need to wait for the item labels to get populated into the chart and then you can adjust their margins. I have pasted some code below that should help you.

public MainPage()
{
  InitializeComponent();
  this.radChart1.LayoutUpdated += this.radChart1_LayoutUpdated;
}
 
void radChart1_LayoutUpdated(object sender, EventArgs e)
{
  var labelsPanel = Telerik.Windows.Controls.ChildrenOfTypeExtensions.FindChildByType<LabelsPanel>(this.radChart1);
  if (labelsPanel == null || labelsPanel.Children.Count == 0)
    return;
        
  this.radChart1.LayoutUpdated -= this.radChart1_LayoutUpdated;
 
  var first = labelsPanel.Children.First();
  var last = labelsPanel.Children.Last();
 
  foreach (SeriesItemLabel seriesItemLabel in labelsPanel.Children)
  {
    if (seriesItemLabel == first || seriesItemLabel == last)
      continue;
 
    double leftAdjustment = -(seriesItemLabel.ActualWidth / 2 + 5);
    seriesItemLabel.Margin = new Thickness(leftAdjustment, 0, 0, 0);
  }
}
 

Regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Yaroslav
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or