public DataPoint(double xValue, string yValues) : base(null, pointAttributes: true) { string[] array = yValues.Split(','); yValue = new double[array.Length]; for (int i = 0; i < array.Length; i++) { yValue[i] = CommonElements.ParseDouble(array[i]); } this.xValue = xValue; }
private double ConvertValue(object value) { if (value == null) { return(0.0); } if (value is double) { return((double)value); } if (value is float) { return((float)value); } if (value is decimal) { return((double)(decimal)value); } if (value is int) { return((int)value); } if (value is uint) { return((uint)value); } if (value is long) { return((long)value); } if (value is ulong) { return((ulong)value); } if (value is byte) { return((int)(byte)value); } if (value is sbyte) { return((sbyte)value); } if (value is bool) { if (!(bool)value) { return(0.0); } return(1.0); } return(CommonElements.ParseDouble(value.ToString())); }
public void SetValueY(params object[] yValue) { if (yValue.Length == 0 || (series != null && yValue.Length > series.YValuesPerPoint)) { throw new ArgumentOutOfRangeException("yValue", SR.ExceptionDataPointYValuesSettingCountMismatch(series.YValuesPerPoint.ToString(CultureInfo.InvariantCulture))); } for (int i = 0; i < yValue.Length; i++) { if (yValue[i] == null || yValue[i] is DBNull) { yValue[i] = 0.0; if (i == 0) { Empty = true; } } } Type type = yValue[0].GetType(); if (series != null) { series.CheckSupportedTypes(type); } if (this.yValue.Length < yValue.Length) { this.yValue = new double[yValue.Length]; } if (type == typeof(string)) { try { for (int j = 0; j < yValue.Length; j++) { this.yValue[j] = CommonElements.ParseDouble((string)yValue[j]); } } catch { if (series != null && series.chart == null && series.serviceContainer != null) { series.chart = (Chart)series.serviceContainer.GetService(typeof(Chart)); } if (series == null || series.chart == null || !series.chart.chartPicture.SuppressExceptions) { throw new ArgumentException(SR.ExceptionDataPointYValueStringFormat); } Empty = true; for (int k = 0; k < yValue.Length; k++) { yValue[k] = 0.0; } } } else if (type == typeof(DateTime)) { for (int l = 0; l < yValue.Length; l++) { if (yValue[l] == null || (yValue[l] is double && (double)yValue[l] == 0.0)) { this.yValue[l] = DateTime.Now.ToOADate(); } else { this.yValue[l] = ((DateTime)yValue[l]).ToOADate(); } } } else { for (int m = 0; m < yValue.Length; m++) { this.yValue[m] = ConvertValue(yValue[m]); } } if (series == null) { return; } for (int n = 0; n < yValue.Length; n++) { if (yValue[n] == null || (yValue[n] is double && (double)yValue[n] == 0.0)) { if (series.YValueType == ChartValueTypes.Date) { this.yValue[n] = Math.Floor(this.yValue[n]); } else if (series.YValueType == ChartValueTypes.Time) { this.yValue[n] = xValue - Math.Floor(this.yValue[n]); } } else if (series.YValueType == ChartValueTypes.Date) { DateTime dateTime = (yValue[n] is DateTime) ? ((DateTime)yValue[n]) : ((!(yValue[n] is double)) ? Convert.ToDateTime(yValue[n], CultureInfo.InvariantCulture) : DateTime.FromOADate((double)yValue[n])); DateTime dateTime2 = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0); this.yValue[n] = dateTime2.ToOADate(); } else if (series.YValueType == ChartValueTypes.Time) { DateTime dateTime3; if (yValue[n] is DateTime) { dateTime3 = (DateTime)yValue[n]; } dateTime3 = ((!(yValue[n] is double)) ? Convert.ToDateTime(yValue[n], CultureInfo.InvariantCulture) : DateTime.FromOADate((double)yValue[n])); DateTime dateTime4 = new DateTime(1899, 12, 30, dateTime3.Hour, dateTime3.Minute, dateTime3.Second, dateTime3.Millisecond); this.yValue[n] = dateTime4.ToOADate(); } } }