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

faking a Trend line

3 Answers 99 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 18 May 2009, 08:05 PM
Ok I am sure this is easy, but I do not get it.

I want to add a trend line to my grid.  I have the value of my first and last point.  How do I put them at the two points I want on the Grid.(frist point and last)

            ChartAxisItem itemFirst = new ChartAxisItem();
            itemFirst.Value = Convert.ToDecimal(firstTrendPoint);
            ChartSalesTrend.PlotArea.YAxis.Items.Add(itemFirst);

           
            ChartAxisItem itemSecond= new ChartAxisItem();
            itemFirst.Value = Convert.ToDecimal(lastTrendPoint);
            ChartSalesTrend.PlotArea.YAxis.Items.Add(itemSecond);

I thought this was it, but I was wrong.  Thanks in advance for your help


3 Answers, 1 is accepted

Sort by
0
Dessy
Telerik team
answered on 20 May 2009, 02:34 PM
Hello Gary,

In order to add Trend Line you could create a new series containing two items (with Y and X values)- your first and last point. Then you should add this series to your RadChart. This will cause RadChart automatically to add the necessary range along the XAxis, so you will not need to populate it manually.

Here is an example:

     ChartSeries series = new ChartSeries();  
     series.Type = ChartSeriesType.Line;  
 
     ChartSeriesItem item = new ChartSeriesItem();  
     item.YValue = Convert.ToDouble(firstTrendPointY);  
     item.XValue=Convert.ToDouble(firstTrendPointX);
     series.AddItem(item);  
 
     ChartSeriesItem item2 = new ChartSeriesItem();  
     item2.YValue = Convert.ToDouble(lastTrendPointY); 
     item2.XValueConvert.ToDouble(lastTrendPointX);
     series.AddItem(item2);  
 
     RadChart1.Series.Add(series); 

Hope this helps.

Regards,
Dessy
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Gary
Top achievements
Rank 1
answered on 20 May 2009, 03:50 PM
 ChartSeries seriesTrend = new ChartSeries("Trend", ChartSeriesType.Line);  
            seriesTrend.Appearance.FillStyle.MainColor = Color.Black;  
            ChartSeriesItem item = new ChartSeriesItem();  
            item.YValue = Convert.ToDouble(11000);  
            item.XValue = Convert.ToDouble(firstXpoint);  
            seriesTrend.AddItem(item);  
 
            ChartSeriesItem item2 = new ChartSeriesItem();  
            item2.YValue = Convert.ToDouble(12000);  
            item2.XValue = Convert.ToDouble(secondXpoint);  
            seriesTrend.AddItem(item2);  
 
            ChartSalesTrend.Series.Add(seriesTrend); 
Well it does not work.  My series is added, but the line does not show up.

Is first Xpoint what I add when I am building the chart? 
 foreach (DataColumn chartServicesColumn in salesData.Tables[0].Columns)  
                    {  
                        setyear = chartServicesColumn.ColumnName;  
                        if (setyear != "FranNum")  
                        {  
                            if (firstPass != true)  
                            {  
                                firstPass = true;  
                                firstTrendPoint = DataUtil.GetDBDouble(chartRow[chartServicesColumn.ColumnName]);  
                                firstXpoint = SbiLib.Text.StringExtensions.Right(chartServicesColumn.ColumnName, 2);  
                            }  
                            ChartSalesTrend.PlotArea.XAxis.AddItem(SbiLib.Text.StringExtensions.Right(chartServicesColumn.ColumnName, 2));  
                            series.AddItem(DataUtil.GetDBDouble(chartRow[chartServicesColumn.ColumnName]));  
                            getRangegetRange = getRange + Convert.ToDecimal((DataUtil.GetDBDouble(chartRow[chartServicesColumn.ColumnName])));  
                            countercounter = counter + 1;  
                            if (counter == counterX)  
                            {  
                                secondXpoint = SbiLib.Text.StringExtensions.Right(chartServicesColumn.ColumnName, 2);  
                                lastTrendPoint = DataUtil.GetDBDouble(chartRow[chartServicesColumn.ColumnName]);  
                            }  
                              
                        }  
                    } 
See when I hit the for loop I grab the first X and Y points, and when I leave I grab the last.
0
Gary
Top achievements
Rank 1
answered on 20 May 2009, 05:04 PM
I got it, thx for your help
Tags
Chart (Obsolete)
Asked by
Gary
Top achievements
Rank 1
Answers by
Dessy
Telerik team
Gary
Top achievements
Rank 1
Share this question
or