faking a Trend line

Thread is closed for posting
4 posts, 0 answers
  1. Gary
    Gary avatar
    21 posts
    Member since:
    Feb 2008

    Posted 18 May 2009 Link to this post

    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


  2. Dessy
    Admin
    Dessy avatar
    73 posts

    Posted 20 May 2009 Link to this post

    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.
  3. Gary
    Gary avatar
    21 posts
    Member since:
    Feb 2008

    Posted 20 May 2009 Link to this post

     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.
  4. Gary
    Gary avatar
    21 posts
    Member since:
    Feb 2008

    Posted 20 May 2009 Link to this post

    I got it, thx for your help
Back to Top