Vertical Line on Radchart

Thread is closed for posting
2 posts, 0 answers
  1. Rakesh
    Rakesh avatar
    6 posts
    Member since:
    Aug 2012

    Posted 28 Feb 2012 Link to this post

    Trying to draw a vertical line with x-axis as Datetime. How to set the X-axis a Constant Date using MarkedZones.

    <MarkedZones> 
                                                                    <telerik:ChartMarkedZone Name="Marked zone 1" >
                                                                        <Appearance> 
                                                                            <Border Width="2" Color="Pink" /> 
                                                                        </Appearance> 
                                                                    </telerik:ChartMarkedZone> 
                                                                </MarkedZones> 
  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 02 Mar 2012 Link to this post

    Hello Rakesh,

    Since the DateTime-s on the XAxis are presented as doubles (using its OLE Automation equivalent - ToOADate() method), you may set this double as starting point for your marked zone. Here's an example:

    protected void Page_Load(object sender, EventArgs e)
       {
           ChartSeries series = new ChartSeries();
           series.DataXColumn = "OADate";
           series.DataYColumn = "YValue";
           radChart1.Series.Add(series);
           radChart1.PlotArea.XAxis.Appearance.ValueFormat = ChartValueFormat.ShortDate;
           radChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 320;
           radChart1.PlotArea.XAxis.IsZeroBased = false;
           radChart1.PlotArea.XAxis.AutoScale = false;
           double startTime = DateTime.Today.ToOADate();
           double endTime = DateTime.Today.AddDays(4).ToOADate();
           radChart1.PlotArea.XAxis.AddRange(startTime, endTime, 1);
           radChart1.DataSource = GetData();
           radChart1.DataBind();
           ChartMarkedZone mzone = new ChartMarkedZone();
           mzone.ValueStartY = 100;
           mzone.ValueEndY = 0;
           mzone.ValueStartX = (double)radChart1.PlotArea.XAxis[2].Value;
           mzone.ValueEndX = (double)radChart1.PlotArea.XAxis[2].Value;
           mzone.Appearance.Border.Color = Color.Red;
           mzone.Appearance.Border.Width = 2;
           radChart1.PlotArea.MarkedZones.Add(mzone);
           radChart1.AutoLayout = true;
       }
       private static List<ChartData> GetData()
       {
           List<ChartData> data = new List<ChartData>();
           data.Add(new ChartData() { Date = DateTime.Today, YValue = 21 });
           data.Add(new ChartData() { Date = DateTime.Today.AddDays(1), YValue = 11 });
           data.Add(new ChartData() { Date = DateTime.Today.AddDays(2), YValue = 15 });
           data.Add(new ChartData() { Date = DateTime.Today.AddDays(3), YValue = 17 });
           data.Add(new ChartData() { Date = DateTime.Today.AddDays(4), YValue = 19 });
           return data;
       }
       public class ChartData
       {
           public double OADate
           {
               get
               {
                   return this.Date.ToOADate();
               }
           }
           public DateTime Date
           {
               get;
               set;
           }
           public double YValue
           {
               get;
               set;
           }
       }

    Greetings,
    Evgenia
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top