Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
How to draw a trend line like excel?
posted

Please help me ,thanks a lot

 How to draw a trend line ? like excel trend line

 

like this-->>

this is my file.cs ,use the Composite Chart ,but i don't know how to draw a trend line

----------------------------------------------------------------------------------------------------
....
using System.Data.OracleClient;
using System.Web.Configuration;
using Infragistics.UltraChart.Shared.Styles;
using Infragistics.UltraChart.Resources.Appearance;
using Infragistics.UltraChart.Core.Layers;
using Infragistics.UltraChart.Resources;

/// <summary>
///
/// </summary>
public partial class DescCurve : System.Web.UI.Page,IRenderLabel
{
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            try
            {
                /*return dataset
                 *
                 *
                    NY                         XHD2       XHA2       XHE2
                    -------------------- ---------- ---------- ----------
                    200001                     6885       1163       6035
                 *
                 *
                */
                OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                string s = "select Ny,sum(case when t.dydm='XHD2' then t.ycyl else 0 end) as XHD2,sum(case when t.dydm='XHA2' then t.ycyl else 0 end) as XHA2,sum(case when t.dydm='XHE2' then t.ycyl else 0 end) as XHE2 FROM pgxx_data_monthly t where ny like '200%' and (t.dydm='XHD2' or t.dydm='XHA2' or t.dydm='XHE2') group by ny order by ny asc";
                OracleDataAdapter sa = new OracleDataAdapter(s, conn);
                conn.Open();
                sa.Fill(ds, "QuerySelect");
                conn.Close();

                // Chart     
                UltraChart1.DataSource = ds;
                UltraChart1.DataBind();
                //Response.Write(ds.Tables[0].Columns[0].ToString());
                //Response.End();
                UltraChart1.ChartType = ChartType.Composite;
                UltraChart1.Width = 1024;
                UltraChart1.Height = 600;
                UltraChart1.TitleTop.Text = "desccurve";
                UltraChart1.EnableCrossHair = true;
                UltraChart1.EmptyChartText = "data false!";

                // add chartarea
                ChartArea myChartArea = new ChartArea();
                UltraChart1.CompositeChart.ChartAreas.Add(myChartArea);

                //add axis
                AxisItem myX = new AxisItem();
                myX.OrientationType = AxisNumber.X_Axis;
                myX.DataType= AxisDataType.String;
                myX.Labels.ItemFormatString = "<ITEM_LABEL>";
                //
                //http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/Chart_Creating_a_Composite_Chart_in_Code_Part_1_of_2.html
                myX.SetLabelAxisType = SetLabelAxisType.ContinuousData;

                AxisItem myY = new AxisItem();
                myY.OrientationType = AxisNumber.Y_Axis;
                myY.DataType = AxisDataType.Numeric;
                myY.Labels.ItemFormatString = "<DATA_VALUE:00.##>";

                myChartArea.Axes.Add(myX);
                myChartArea.Axes.Add(myY);

                //add series to Series collection.
                NumericSeries myseries1 = new NumericSeries();
                myseries1.Label = "SeriesA";
                //data bound
                myseries1.Data.DataSource = ds.Tables[0];
                myseries1.Data.LabelColumn = ds.Tables[0].Columns[0].ToString();
                myseries1.Data.ValueColumn = ds.Tables[0].Columns[1].ToString();
                //myseries1.Data.LabelColumn = "NY";
                //myseries1.Data.ValueColumn = "XHD2";
                UltraChart1.CompositeChart.Series.Add(myseries1);

                NumericSeries myseries2 = new NumericSeries();
                myseries2.Label = "SeriesB";
                myseries2.Data.DataSource = ds.Tables[0];
                myseries2.Data.LabelColumn = ds.Tables[0].Columns[0].ToString();
                myseries2.Data.ValueColumn = ds.Tables[0].Columns[2].ToString();
                UltraChart1.CompositeChart.Series.Add(myseries2);

                NumericSeries myseries3 = new NumericSeries();
                myseries3.Label = "SeriesC";
                myseries3.Data.DataSource = ds.Tables[0];
                myseries3.Data.LabelColumn = ds.Tables[0].Columns[0].ToString();
                myseries3.Data.ValueColumn = ds.Tables[0].Columns[3].ToString();
                UltraChart1.CompositeChart.Series.Add(myseries3);

                //add chart layer
                ChartLayerAppearance mylayer = new ChartLayerAppearance();
                mylayer.ChartType = ChartType.LineChart;
                mylayer.ChartArea = myChartArea;
                mylayer.AxisX = myX;
                mylayer.AxisY = myY;
                mylayer.Series.Add(myseries1);
                mylayer.Series.Add(myseries2);
                mylayer.Series.Add(myseries3);
                this.UltraChart1.CompositeChart.ChartLayers.Add(mylayer);

                //custom Tooltips 

                UltraChart1.Tooltips.Display = TooltipDisplay.MouseMove; 
                UltraChart1.Tooltips.Format = TooltipStyle.Custom;
                UltraChart1.Tooltips.FormatString = "<CUSTOM>";
                Hashtable labelHash = new Hashtable();
                labelHash.Add("CUSTOM", this);
                this.UltraChart1.LabelHash = labelHash;
            }
            finally
            {

            }
        }
    }

    #region IRenderLabel

    string IRenderLabel.ToString(Hashtable Context)
    {
        double displayY=(double)Context["DATA_VALUE"];
        string dispayX=(string)Context["ITEM_LABEL"];
        string customLabel = "";
        //return label 
        customLabel = displayY + "," +dispayX ;
        //customLabel = "OK";
        return customLabel;
    }

    #endregion

  • 125
    posted

    You can also create a composite chart with multiple line charts as layers. Each layer can take a line bound to a certain data column. Calculate the trend using your raw data and place it into an easily accessible data column. Using a NumericSeries object, collect that info and bind the NumericSeries to a chart layer.

  • 26458
    Offline posted

    Unfortunately, since the chart does not offer any data analysis, such functionality is not built into the chart. However, adding custom shapes to the chart is not difficult. If you can extract x and y coordinates from the data for your trend line, you can create a Polyline primitive, handle FillSceneGraph event of the chart and add the primitive to the e.SceneGraph collection.