VerticalLineAnnotation with 2 Horizontal Labels

Hi, 

I would like to create a vertical line annotation with a label on each side that is horizontal and placed at the top of the chart. I've attached an image to clarify.

Attachment: trendlinedemo_f1c54a6.zip

7 Replies

DS Durgadevi Selvaraj Syncfusion Team February 22, 2018 11:51 AM UTC


Hi Sean, 
 
Thanks for contacting Syncfusion Support. 
 
You can achieve this requirement by using ContentTemplate of VerticalLineAnnotation. In that template, you can define a TextBlocks to display Text on both side of Vertical line annotation. 
 
Please refer the below code, 
 
Code Snippet[XAML] 
  <chart:SfChart.Annotations> 
                <chart:VerticalLineAnnotation X1="2" Stroke="DarkGray" StrokeThickness="5"> 
                    <chart:VerticalLineAnnotation.ContentTemplate> 
                        <DataTemplate> 
                            <StackPanel > 
                                <TextBlock Text="Title 1" Margin="0,-50,0,0"> 
                                    <TextBlock.RenderTransform> 
                                        <RotateTransform Angle="90"/> 
                                    </TextBlock.RenderTransform> 
                                </TextBlock> 
                                <TextBlock Text="Title 2" Margin="0,50,0,0" > 
                                    <TextBlock.RenderTransform> 
                                        <RotateTransform Angle="90"/> 
                                    </TextBlock.RenderTransform> 
                                </TextBlock> 
                            </StackPanel> 
                        </DataTemplate> 
                    </chart:VerticalLineAnnotation.ContentTemplate> 
                </chart:VerticalLineAnnotation> 
</chart:SfChart.Annotations> 
 
Please refer the reference output screenshot below, 
 
You can download the sample for this requirement from below location, 
 
Also, you can refer our UG Documentation link to know more about annotations in SfChart from below link, 
 
Regards,  
Durgadevi S 



SS Sean Schellinger February 22, 2018 05:51 PM UTC

Thanks Durgadevi. This would work, but I'm creating this annotations in the code behind after the control is initialized. I am able to apply the template, but I need to be able to programatically set the text in each textbox. These are static once set so it can be accomplished via binding or manually. Can you provide an example of this?


SS Sean Schellinger February 23, 2018 03:30 PM UTC

I found that your solution didn't exactly work since the margin would have to be calculated based on text length. This can be done, but I think I found an easier way. I can simply put two annotation on top of each other with one having text on the right and one on the left. How would I rotate these labels? 


DS Durgadevi Selvaraj Syncfusion Team February 26, 2018 07:20 AM UTC

Hi Sean, 
  
Thanks for the update. 
  
You can rotate the text of TextAnnotation by using of Angle property in TextAnnotation as like in below code, 
  
Code Snippet[XAML] 
   <chart:TextAnnotation Text="Title 1" X1="1.5" Y1="57" Angle="90"/> 
  
Please refer our UG documentation link to know about this property, 
  
Regards,  
Durgadevi S 



SS Sean Schellinger February 28, 2018 08:33 PM UTC

I am still using the VerticalLineAnnotation though. For instance:

<code>
VerticalLineAnnotation currentAnnotation = new VerticalLineAnnotation()
                {
                    X1 = viewModel.CardTimestamps.ElementAt(i),
                    Text = viewModel.DebriefCards.ElementAt(i).CardTitle,
                    HorizontalTextAlignment = HorizontalAlignment.Right,
                    Stroke = new SolidColorBrush(Colors.Black),
                    StrokeThickness = 4,
                    Opacity = 0.2,
                };
                //currentAnnotation.ContentTemplate = template;
                waveformsGraph.Annotations.Add(currentAnnotation);
                if(i > 0)
                {
                    VerticalLineAnnotation previousAnnotation = new VerticalLineAnnotation()
                    {
                        X1 = viewModel.CardTimestamps.ElementAt(i),
                        Text = viewModel.DebriefCards.ElementAt(i-1).CardTitle,
                        HorizontalTextAlignment = HorizontalAlignment.Left,
                        Stroke = new SolidColorBrush(Colors.Black),
                        StrokeThickness = 4,
                        Opacity = 0.2  ,
                    };
                    //previousAnnotation.ContentTemplate = template;
                    waveformsGraph.Annotations.Add(previousAnnotation);
</code>

Is it possible to rotate this text?

(Sorry not sure how to format as code)


SS Sean Schellinger replied to Sean Schellinger March 8, 2018 08:32 PM UTC

I am still using the VerticalLineAnnotation though. For instance:

<code>
VerticalLineAnnotation currentAnnotation = new VerticalLineAnnotation()
                {
                    X1 = viewModel.CardTimestamps.ElementAt(i),
                    Text = viewModel.DebriefCards.ElementAt(i).CardTitle,
                    HorizontalTextAlignment = HorizontalAlignment.Right,
                    Stroke = new SolidColorBrush(Colors.Black),
                    StrokeThickness = 4,
                    Opacity = 0.2,
                };
                //currentAnnotation.ContentTemplate = template;
                waveformsGraph.Annotations.Add(currentAnnotation);
                if(i > 0)
                {
                    VerticalLineAnnotation previousAnnotation = new VerticalLineAnnotation()
                    {
                        X1 = viewModel.CardTimestamps.ElementAt(i),
                        Text = viewModel.DebriefCards.ElementAt(i-1).CardTitle,
                        HorizontalTextAlignment = HorizontalAlignment.Left,
                        Stroke = new SolidColorBrush(Colors.Black),
                        StrokeThickness = 4,
                        Opacity = 0.2  ,
                    };
                    //previousAnnotation.ContentTemplate = template;
                    waveformsGraph.Annotations.Add(previousAnnotation);
</code>

Is it possible to rotate this text?

(Sorry not sure how to format as code)

Disregard this. I was able to make two separate templates that I assign programatically to solve my issue.


MK Muneesh Kumar G Syncfusion Team March 9, 2018 11:18 AM UTC

Hi Sean, 
 
Thanks for the update. 
  
We are glad to know that the given solution worked. Please get back to us if you need further assistance. 
 
Thanks, 
Muneesh Kumar G. 
 


Loader.
Up arrow icon