/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="color"></param> private CurveData CreateAndAddCurveData(string name, Color color) { CurveData cd = new CurveData(); cd.Name = name; cd.Color = color; this.CurveDataMap.Add(name, cd); return(cd); }
/// <summary> /// /// </summary> /// <param name="dataSource"></param> /// <returns></returns> public override CurveDataCollection Create(object dataSource) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } this.CurveDataMap.Clear(); ColorProvider cp = new ColorProvider(); DataTable tbl = dataSource as DataTable; foreach (DataRow row in tbl.Rows) { CurveData cd = null; string name = row[NameField].ToString(); if (HasCurveData(name)) { cd = GetCurveData(name); } else { cd = CreateAndAddCurveData(name, cp.GetNextColor()); PointPairList list = new PointPairList(); cd.PointList = list; } object obj = row[XDataField]; DateTime dt = Convert.ToDateTime(obj); XDate xdate = new XDate(dt); obj = row[YDataField]; double y = Convert.ToDouble(obj); ((PointPairList)cd.PointList).Add(xdate.XLDate, y); } CurveDataCollection cds = new CurveDataCollection(); foreach (object cdObj in this.CurveDataMap.Values) { cds.Add(cdObj as CurveData); } return(cds); }
/// <summary> /// /// </summary> /// <param name="dataSource"></param> /// <returns></returns> public override CurveDataCollection Create(object dataSource) { //DataTable tbl = dataSource as DataTable; //foreach (DataRow row in tbl.Rows) //{ // object objX = row[XDataField]; // object objY = row[YDataField]; //} if (this.CurveConfigBaseCollection == null) { throw new InvalidOperationException("sineleCurveConfig.CurveConfigBaseCollection == null"); } if (this.CurveConfigBaseCollection.GraphPaneConfig == null) { throw new InvalidOperationException("sineleCurveConfig.CurveConfigBaseCollection.GraphPaneConfig == null"); } AxisType axisType = this.CurveConfigBaseCollection.GraphPaneConfig.XAxisType; DataTable tbl = dataSource as DataTable; if (axisType == AxisType.Date) { PointPairList list = new PointPairList(); // TODO: is line // foreach (DataRow row in tbl.Rows) { object obj = row[XDataField]; // TODO: 2011-06-13 not datetime data // DateTime dt = Convert.ToDateTime(obj); XDate xdate = new XDate(dt); obj = row[YDataField]; double y = Convert.ToDouble(obj); list.Add(xdate.XLDate, y); } CurveData cd = new CurveData(); cd.Name = this.Name; cd.Color = this.Color; cd.PointList = list; CurveDataCollection cds = new CurveDataCollection(); cds.Add(cd); return(cds); } else if (axisType == AxisType.Text) { string[] labels = new string[tbl.Rows.Count]; double[] yvalues = new double[tbl.Rows.Count]; for (int i = 0; i < tbl.Rows.Count; i++) { DataRow row = tbl.Rows[i]; string lbl = row[XDataField].ToString(); labels[i] = lbl; yvalues[i] = Convert.ToDouble(row[YDataField]); } CurveData cd = new CurveData(); cd.Name = this.Name; cd.Color = this.Color; cd.XAxisLabels = labels; cd.YValues = yvalues; CurveDataCollection cds = new CurveDataCollection(); cds.Add(cd); return(cds); } else { throw new NotImplementedException("not support AxisType: " + axisType); } }