Marked Zones at Run Time

2 posts, 0 answers
  1. John
    John avatar
    5 posts
    Member since:
    Jan 2012

    Posted 24 Jan 2012 Link to this post

    How do I go about adding marked zones at run time in the code behind? I've found the examples using xaml, but my zones will be determined at run time based on the data.
  2. Nikolay
    Admin
    Nikolay avatar
    385 posts

    Posted 27 Jan 2012 Link to this post

    Hello John,

    Please, consider the following approach, using a DispatcherTimer.

    Adding the chart :
    <telerik:RadChart Name="RadChart1" />

    In code behind :
    public MainPage()
            {
                InitializeComponent();
      
                Binding ann = new Binding();
                ann.Source = new ViewModel();
                ann.Path = new PropertyPath("Annotations");
      
                RadChart1.DefaultView.ChartArea.SetBinding(ChartArea.AnnotationsProperty, ann);
                RadChart1.DefaultSeriesDefinition = new LineSeriesDefinition();
      
                DispatcherTimer timer = new DispatcherTimer();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = TimeSpan.FromSeconds(3);
                timer.Start();
            }
      
            private Random rand = new Random(123456);
      
            void timer_Tick(object sender, EventArgs e)
            {
                RadChart1.ItemsSource = new int[] { rand.Next(100, 150), rand.Next(100, 150), rand.Next(100, 150) };
            }

    and the ViewModel :
    public class ViewModel
        {
            public AnnotationCollection Annotations
            {
                get
                {
                    var col = new AnnotationCollection();
                    col.Add(new CustomGridLine() { YIntercept = 120, Stroke = new SolidColorBrush(Colors.Red) });
      
                    return col;
                }
            }
        }

    Hopt his helps.

    Kind regards,
    Nikolay
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
Back to Top