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

Marked Zones at Run Time

1 Answer 36 Views
Chart
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 24 Jan 2012, 05:27 PM
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.

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 27 Jan 2012, 08:49 AM
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 >>
Tags
Chart
Asked by
John
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or