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

CartesianCustomLineAnnotation : Unable to view on RadCartesianChart

3 Answers 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nitin Nitin
Top achievements
Rank 1
Nitin Nitin asked on 14 Aug 2013, 12:35 PM
Hello,

I have a radcartesianchart and am trying to add a cartesiancustomlineannotation in it.

Following is my xaml page:
<UserControl x:Class="SL_708313_DragCustomLineAnnotation.RadCartChartForAnnotaionTest"
    mc:Ignorable="d" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    d:DesignHeight="300" d:DesignWidth="400">
     
    <Grid x:Name="LayoutRoot" Background="Black">
        <telerik:RadCartesianChart x:Name="xRadCartesianChart">
        </telerik:RadCartesianChart>
    </Grid>
</UserControl>


And my code behind :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.ChartView;
using System.Collections.ObjectModel;
using Telerik.Charting;
using Telerik.Windows.Controls;
 
namespace SL_708313_DragCustomLineAnnotation
{
    public partial class RadCartChartForAnnotaionTest : UserControl
    {
        private ObservableCollection<TrendsLineSeriesChartData> m_listOfDataPoints;
        public ObservableCollection<TrendsLineSeriesChartData> ListOfDataPoints
        {
            get { return m_listOfDataPoints; }
            set { m_listOfDataPoints = value; }
        }
 
        public RadCartChartForAnnotaionTest()
        {
            InitializeComponent();
            CreateDummyDataForChart();
        }
 
        public void CreateDummyDataForChart()
        {
            ObservableCollection<TrendsLineSeriesChartData> chartData = new ObservableCollection<TrendsLineSeriesChartData>();
            LinearAxis verticalAxis = new LinearAxis();
            verticalAxis.Minimum = 0;
            verticalAxis.Maximum = 100;
            verticalAxis.MajorStep = Math.Round(verticalAxis.Maximum / 10);
            verticalAxis.Visibility = Visibility.Visible;
 
            DateTimeContinuousAxis horizontalAxis = new DateTimeContinuousAxis();
            horizontalAxis.Visibility = Visibility.Visible;
            horizontalAxis.MajorStepUnit = TimeInterval.Day;
 
            LineSeries scatterlineSeries = new LineSeries();
            scatterlineSeries.Name = "Series01";
            scatterlineSeries.ValueBinding = new PropertyNameDataPointBinding("LineSeriesChartValue");
            scatterlineSeries.CategoryBinding = new PropertyNameDataPointBinding("LineSeriesChartCategory");
            scatterlineSeries.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack;
            scatterlineSeries.VerticalAxis = verticalAxis;
            scatterlineSeries.HorizontalAxis = horizontalAxis;
                         
            Random rnd = new Random();
            DateTime dt = new DateTime();
            dt = DateTime.Now;
            DateTime temp;
            temp = dt.AddDays(3);
            for (int i = 1; i <= 10; i++)
            {
                TrendsLineSeriesChartData dataPoint = new TrendsLineSeriesChartData();
                double number = rnd.Next(10, 100);
                dataPoint.LineSeriesChartCategory = dt.AddDays(i);
                dataPoint.LineSeriesChartValue = number;
                chartData.Add(dataPoint);
            }
            scatterlineSeries.ItemsSource = chartData;
            xRadCartesianChart.Series.Add(scatterlineSeries);
            AddRuler(temp);
 
        }
 
        private void AddRuler(DateTime horiToAndFrom)
        {
            CartesianCustomLineAnnotation annotation = new CartesianCustomLineAnnotation();
            annotation.VerticalFrom = Convert.ToDouble(0);
            annotation.VerticalTo = Convert.ToDouble(50);
            annotation.HorizontalFrom = horiToAndFrom.ToString(); //Convert.ToDateTime("09-08-2013 00:00:00");
            annotation.HorizontalTo = horiToAndFrom.ToString(); //Convert.ToDateTime("09-08-2013 00:00:00");
            annotation.IsHitTestVisible = true;
            annotation.Stroke = new SolidColorBrush(Colors.Red);
            annotation.StrokeThickness = 3;
            annotation.VerticalAxis = xRadCartesianChart.Series[0].VerticalAxis;
            annotation.HorizontalAxis = xRadCartesianChart.Series[0].HorizontalAxis;
            xRadCartesianChart.Annotations.Add(annotation);
        }
    }
}
 
public class TrendsLineSeriesChartData
{
 
    public double LineSeriesChartValue
    {
        get { return m_LineSeriesChartValue; }
        set { m_LineSeriesChartValue = value; }
    }
 
    private double m_LineSeriesChartValue;
    public DateTime LineSeriesChartCategory
    {
        get { return m_LineSeriesChartCategory; }
        set { m_LineSeriesChartCategory = value; }
    }
 
    private DateTime m_LineSeriesChartCategory;
}

I dont know whats going wrong in the above.

Can you please correct me in the code above..

I am using DateTimeContinousAxis as Horizontal Axis. Later I will be formatting the x-axis string to hh:mm or dd:MMM or anything else.

I would like to add the annotation in all the scenarios of x-axis string formatting.

Any early help would be really appreciated. Very urgent.

thanks,
Nitin



3 Answers, 1 is accepted

Sort by
0
Nitin Nitin
Top achievements
Rank 1
answered on 14 Aug 2013, 12:37 PM
It would be helpful also if you could provide me a solution to the above problem.

Thanks
0
Nitin Nitin
Top achievements
Rank 1
answered on 15 Aug 2013, 09:11 AM
Hello Telerik,

Can you please reply to question. It is very urgent.

Thanks,
Nitin
0
Nitin Nitin
Top achievements
Rank 1
answered on 15 Aug 2013, 05:45 PM
I am still not able to draw custom line annotation..
can you pls give me a solution with horizontal axis as datetimecontinousaxis with different datetime formats like dd:MM, dd:MMM, MM:YYYY, etc

Thanks,
Nitn R
Tags
General Discussions
Asked by
Nitin Nitin
Top achievements
Rank 1
Answers by
Nitin Nitin
Top achievements
Rank 1
Share this question
or