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

Chart X-Axis ToOADate Date Label Issue

1 Answer 184 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Sir
Top achievements
Rank 1
Sir asked on 02 Nov 2009, 09:10 PM
Hi, I have telerik ver 2009.02.0817.20

I have an area chart where my x-axis labels are dates using .ToOADate().
I found the code example on your site and it was working at one point early on.
I can't figure out for the life of me now what is wrong.
No matter what I do, the x-axis date lables are all showing up as the .ToOADate():  i.e. the label is "40096" instead of "10/10/2009".
The chartDay.Date, this.ChartStartDate, & this.ChartEndDate are all valid dates and all set to exactly midnight.
Here is my code, where am I going wrong????

<RadControl:RadChart ID="RadChartControl" SeriesOrientation="Vertical" runat="server" Skin="Web20" Height="225px" Width="777px" Visible="true" ChartTitle-Visible="false"></RadControl:RadChart> 

        private void PlotChart(System.Collections.Generic.List<LoanEventResponseTimeChartItem> chartData)  
        {  
            this.RadChartControl.Appearance.TextQuality = Telerik.Charting.Styles.TextQuality.AntiAlias;  
            this.RadChartControl.ChartTitle.TextBlock.Text = "Loan Event Average Response Time by Day";  
            this.RadChartControl.Series.Clear();  
 
            if (chartData != null && chartData.Count > 0)  
            {  
                Telerik.Charting.ChartSeries chartSeries = new Telerik.Charting.ChartSeries();  
                chartSeries.Name = "Loan Event Average Response Time";  
                chartSeries.Type = Telerik.Charting.ChartSeriesType.Area;  
                chartSeries.Appearance.ShowLabels = true;  
                chartSeries.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.Black;  
                chartSeries.Appearance.PointMark.Visible = true;// To enable tooltips  
                this.RadChartControl.Series.Add(chartSeries);  
 
                foreach (LoanEventResponseTimeChartItem chartDay in chartData)  
                {  
                    Telerik.Charting.ChartSeriesItem chartItem = new Telerik.Charting.ChartSeriesItem();  
                    chartItem.XValue = chartDay.Date.ToOADate();  
                    chartItem.YValue = chartDay.AvgResponseTimeSecs;  
                    if (chartDay.AvgResponseTimeSecs > 0)  
                    {  
                        chartItem.Label.TextBlock.Appearance.AutoTextWrap = Telerik.Charting.Styles.AutoTextWrap.True;  
                        chartItem.Label.TextBlock.Appearance.Position.Auto = true;  
                        chartItem.Label.TextBlock.Text = chartDay.AvgResponseTimeSecs.ToString();  
                        // Tooltip  
                        chartItem.PointAppearance.Visible = true;// To enable tooltips  
                        chartItem.PointAppearance.Border.Width = (float)1;  
                        chartItem.PointAppearance.Border.Color = System.Drawing.Color.White;  
                        chartItem.PointAppearance.Dimensions.AutoSize = false;  
                        chartItem.ActiveRegion.Tooltip = "Average of " + chartDay.TotalLoanEventCount.ToString("#,###,####,###") + " Loan Events";  
                    }  
                    else 
                    {  
                        chartItem.Label.TextBlock.Text = "";  
                        chartItem.Label.Visible = false;  
                        chartItem.PointAppearance.Visible = false;  
                    }  
                    this.RadChartControl.Series[0].Items.Add(chartItem);  
                }  
 
                this.RadChartControl.Series[0].Appearance.LegendDisplayMode = Telerik.Charting.ChartSeriesLegendDisplayMode.Nothing;  
 
                const double dayStep = 1;  
                //const double hourStep = 1 / 24.0;  
                //const double minuteStep = hourStep / 60;  
                //const double fiveMinuteStep = minuteStep * 5;  
                this.RadChartControl.PlotArea.XAxis.AddRange(this.ChartStartDate.ToOADate(), this.ChartEndDate.ToOADate(), dayStep);  
 
            }  
 
            this.RadChartControl.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Inside;  
            this.RadChartControl.PlotArea.XAxis.AutoScale = false;  
            this.RadChartControl.PlotArea.XAxis.IsZeroBased = false;  
            this.RadChartControl.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate;  
            this.RadChartControl.PlotArea.XAxis.Appearance.CustomFormat = "MM/dd/yyyy";  
            this.RadChartControl.PlotArea.XAxis.Appearance.MajorGridLines.Visible = false;  
            this.RadChartControl.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = (float)45;  
            this.RadChartControl.PlotArea.XAxis.Appearance.LabelAppearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Top;  
            this.RadChartControl.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font = new System.Drawing.Font("Ariel", 8);  
            this.RadChartControl.PlotArea.YAxis.IsZeroBased = false;  
 
            this.RadChartControl.PlotArea.EmptySeriesMessage.TextBlock.Text = "No data is available for the given criteria";  
            this.RadChartControl.PlotArea.Appearance.Dimensions.Margins.Top = Telerik.Charting.Styles.Unit.Pixel(0);  
            this.RadChartControl.PlotArea.Appearance.Dimensions.Margins.Bottom = Telerik.Charting.Styles.Unit.Pixel(68);  
            this.RadChartControl.PlotArea.Appearance.Dimensions.Margins.Left = Telerik.Charting.Styles.Unit.Pixel(55);  
            this.RadChartControl.PlotArea.Appearance.Dimensions.Margins.Right = Telerik.Charting.Styles.Unit.Pixel(0);  
 
            if (chartData == null || chartData.Count < 1)  
            {  
                this.RadChartControl.PlotArea.YAxis.AutoScale = false;  
                this.RadChartControl.PlotArea.YAxis.MaxValue = 0;  
                this.RadChartControl.PlotArea.YAxis.MinValue = 0;  
            }  
 
            this.RadChartControl.DataBind();  
        }  
 


Thanks,
Ray

1 Answer, 1 is accepted

Sort by
0
Sir
Top achievements
Rank 1
answered on 03 Nov 2009, 01:11 AM
Issue Solved...
For some reason, the order of the code lines makes a big difference.
I moved the .AddRange command under the other PlotArea.XAxis commands, and all is well in the world.

 
            this.RadChartControl.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Inside;  
            this.RadChartControl.PlotArea.XAxis.AutoScale = false;  
            this.RadChartControl.PlotArea.XAxis.IsZeroBased = false;  
            this.RadChartControl.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate;  
            this.RadChartControl.PlotArea.XAxis.Appearance.CustomFormat = "MM/dd/yyyy";  
            this.RadChartControl.PlotArea.XAxis.Appearance.MajorGridLines.Visible = false;  
            this.RadChartControl.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = (float)45;  
            this.RadChartControl.PlotArea.XAxis.Appearance.LabelAppearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Top;  
            this.RadChartControl.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font = new System.Drawing.Font("Ariel", 8);  
            this.RadChartControl.PlotArea.YAxis.IsZeroBased = false;  
 
            const double dayStep = 1;  
            //const double hourStep = 1 / 24.0;  
            //const double minuteStep = hourStep / 60;  
            //const double fiveMinuteStep = minuteStep * 5;  
            this.RadChartControl.PlotArea.XAxis.AddRange(this.ChartStartDate.ToOADate(), this.ChartEndDate.ToOADate(), dayStep);  
 
 

 

The above now works.

Tags
Chart (Obsolete)
Asked by
Sir
Top achievements
Rank 1
Answers by
Sir
Top achievements
Rank 1
Share this question
or