public void ConvertSoilToDataTable() { Soil Soil = new Soil(); Soil.ApsoilNumber = "100"; Soil.Water.Thickness = new double[] { 150.00, 150.00, 300.00, 300.00, 300.00 }; Soil.Water.BD = new double[] { 1.02, 1.03, 1.02, 1.02, 1.06 }; Soil.Water.BDMetadata = new string[] { "Field measured and checked for sensibility", "Laboratory measured", "", "", "" }; Soil.Water.AirDry = new double[] { 0.15, 0.26, 0.29, 0.29, 0.30 }; Soil.Water.LL15 = new double[] { 0.29, 0.29, 0.29, 0.29, 0.30 }; Soil.Water.DUL = new double[] { 0.54, 0.53, 0.54, 0.54, 0.52 }; Soil.Water.SAT = new double[] { 0.59, 0.58, 0.59, 0.58, 0.57 }; Soil.Water.Crops.Add(new SoilCrop() { Name = "Barley", Thickness = new double[] { 100.00, 100.00 }, LL = new double[] { 0.29, 0.25 }, KL = new double[] { 0.10, 0.08 }, XF = new double[] { 1.00, 1.00 } }); Soil.Water.Crops.Add(new SoilCrop() { Name = "Chickpea", Thickness = new double[] { 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00 }, LL = new double[] { 0.29, 0.29, 0.36, 0.43, 0.51, 0.50, 0.50, 0.48 }, KL = new double[] { 0.10, 0.10, 0.08, 0.06, 0.04, 0.02, 0.01, 0.00 }, XF = new double[] { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.00 } }); Soil.SoilOrganicMatter.Thickness = new double[] { 200.000, 200.00 }; Soil.SoilOrganicMatter.OC = new double[] { 1.040, 0.89 }; Soil.SoilOrganicMatter.FBiom = new double[] { 0.025, 0.02 }; Soil.SoilOrganicMatter.FInert = new double[] { 0.400, 0.89 }; Soil.InitialWater = new InitialWater(); Soil.InitialWater.SetSW(0.5, InitialWater.PercentMethodEnum.FilledFromTop); Soil.SoilWater = new SoilWater(); Soil.SoilWater.SummerCona = 3.5; Soil.SoilWater.WinterCona = 3.5; Soil.Analysis.Thickness = new double[] { 100, 100, 100 }; Soil.Analysis.EC = new double[] { 1.7, double.NaN, double.NaN }; DataTable Table = new DataTable(); SoilDataTable.SoilToTable(Soil, Table); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "Thickness (mm)"), Soil.Water.Thickness, 1); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "BD (g/cc)"), Soil.Water.BD, 0.01); Assert.AreEqual(DataTableUtility.GetColumnAsStrings(Table, "BDCode")[0], "FM"); Assert.AreEqual(DataTableUtility.GetColumnAsStrings(Table, "BDCode")[1], "LM"); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "Chickpea ll (mm/mm)"), new double[] { 0.29, 0.29, 0.36, 0.43, 0.51, 0.50, 0.50, 0.48 }, 0.01); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "Chickpea xf (0-1)"), new double[] { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.00 }, 0.01); }
/// <summary> /// Return an array of values for the specified column. /// </summary> private static string[] GetStringValues(DataTable Table, string VariableName, int NumRows, int StartRow) { if (Table.Columns.Contains(VariableName)) { string[] Values = DataTableUtility.GetColumnAsStrings(Table, VariableName, NumRows, StartRow); if (MathUtility.ValuesInArray(Values)) { return(Values); } } return(null); }
static private string[] GetStringValues(DataTable Table, string FieldName, int NumValues, int Row) { // Get string value from specified table for specified field. if (Table.Columns.IndexOf(FieldName) != -1) { return(DataTableUtility.GetColumnAsStrings(Table, FieldName, NumValues, Row)); } else { return(new string[0]); } }
public override void OnSave() { FactorTargets.OnSave(); XmlDocument doc = new XmlDocument(); doc.LoadXml(FactorTargets.GetData()); Data.InnerXml = doc.DocumentElement.InnerXml; if (Table != null) { XmlNode variablesNode = Data.SelectSingleNode("//vars"); if (variablesNode == null) { variablesNode = Data.AppendChild(Data.OwnerDocument.CreateElement("vars")); } variablesNode.RemoveAll(); if (Table.Rows.Count >= 10000) { string[] values = DataTableUtility.GetColumnAsStrings(Table, Table.Columns[0].ColumnName); string csvValue = ""; foreach (string value in values) { if (value != "") { if (csvValue != "") { csvValue += ","; } csvValue += value; } else { break; } } XmlNode varNode = variablesNode.AppendChild(Data.OwnerDocument.CreateElement(Table.Columns[0].ColumnName)); varNode.InnerText = csvValue; } else { foreach (DataRow row in Table.Rows) { if ((bool)row[0]) { XmlNode varNode = variablesNode.AppendChild(Data.OwnerDocument.CreateElement(row[1].ToString())); varNode.InnerText = row[3].ToString(); } } } } }
/// <summary> /// Return a list of code values for the specified variable. /// </summary> private static string[] GetCodeValues(DataTable Table, string VariableName, int NumRows, int StartRow) { if (!Table.Columns.Contains(VariableName)) { return(null); } string[] Codes = DataTableUtility.GetColumnAsStrings(Table, VariableName, NumRows, StartRow); for (int i = 0; i != Codes.Length; i++) { StringManip.SplitOffBracketedValue(ref Codes[i], '(', ')'); } Codes = APSIMChangeTool.CodeToMetaData(Codes); if (MathUtility.ValuesInArray(Codes)) { return(Codes); } return(null); }
/// <summary> /// Fill the specified SoilNode with data from the specified table. /// </summary> public static Soil[] TableToSoils(DataTable Table, ProgressNotifier Notifier = null) { List <Soil> Soils = new List <Soil>(); string[] Names = DataTableUtility.GetColumnAsStrings(Table, "Name"); if (Names.Length == 0) { throw new Exception("Cannot find a name column in spreadsheet"); } // Loop through all blocks of rows in datatable from XLS, create a // soil and store soil in correct location in the AllSoils XML. int StartRow = 0; int counter = 0; while (StartRow < Table.Rows.Count) { // Calculate how many rows for this soil int NumRows = 1; for (int i = StartRow + 1; i < Names.Length; i++) { if (Names[i] == Names[StartRow]) { NumRows++; } else { break; } } Soil NewSoil = new Soil(); Soils.Add(NewSoil); NewSoil.Name = Names[StartRow]; NewSoil.Country = GetStringValue(Table, StartRow, "Country"); NewSoil.State = GetStringValue(Table, StartRow, "State"); NewSoil.Region = GetStringValue(Table, StartRow, "Region"); NewSoil.NearestTown = GetStringValue(Table, StartRow, "NearestTown"); NewSoil.Site = GetStringValue(Table, StartRow, "Site"); NewSoil.ApsoilNumber = GetStringValue(Table, StartRow, "APSoilNumber"); NewSoil.SoilType = GetStringValue(Table, StartRow, "Soil type texture or other descriptor"); NewSoil.LocalName = GetStringValue(Table, StartRow, "LocalName"); NewSoil.ASCOrder = GetStringValue(Table, StartRow, "ASC_Order"); NewSoil.ASCSubOrder = GetStringValue(Table, StartRow, "ASC_Sub-order"); NewSoil.Latitude = GetDoubleValue(Table, StartRow, "Latitude"); NewSoil.Longitude = GetDoubleValue(Table, StartRow, "Longitude"); NewSoil.LocationAccuracy = GetStringValue(Table, StartRow, "LocationAccuracy"); NewSoil.YearOfSampling = GetIntegerValue(Table, StartRow, "YearOfSampling"); NewSoil.DataSource = GetStringValue(Table, StartRow, "DataSource"); NewSoil.Comments = GetStringValue(Table, StartRow, "Comments"); NewSoil.NaturalVegetation = GetStringValue(Table, StartRow, "NaturalVegetation"); NewSoil.RecordNumber = GetIntegerValue(Table, StartRow, "RecordNo"); NewSoil.Analysis.MunsellColour = GetStringValues(Table, "MunsellColour", NumRows, StartRow); NewSoil.Analysis.MunsellMetadata = GetCodeValues(Table, "MunsellColourCode", NumRows, StartRow); NewSoil.Water.Thickness = MathUtility.RemoveMissingValuesFromBottom(GetDoubleValues(Table, "Thickness (mm)", NumRows, StartRow)); int NumLayers = NewSoil.Water.Thickness.Length; NewSoil.Water.BD = GetDoubleValues(Table, "BD (g/cc)", NumLayers, StartRow); NewSoil.Water.BDMetadata = GetCodeValues(Table, "BDCode", NumLayers, StartRow); NewSoil.Analysis.Rocks = GetDoubleValues(Table, "Rocks (%)", NumRows, StartRow); NewSoil.Analysis.RocksMetadata = GetCodeValues(Table, "RocksCode", NumRows, StartRow); NewSoil.Analysis.Texture = GetStringValues(Table, "Texture", NumRows, StartRow); NewSoil.Analysis.TextureMetadata = GetCodeValues(Table, "TextureCode", NumRows, StartRow); NewSoil.Water.SAT = GetDoubleValues(Table, "SAT (mm/mm)", NumLayers, StartRow); NewSoil.Water.SATMetadata = GetCodeValues(Table, "SATCode", NumLayers, StartRow); NewSoil.Water.DUL = GetDoubleValues(Table, "DUL (mm/mm)", NumLayers, StartRow); NewSoil.Water.DULMetadata = GetCodeValues(Table, "DULCode", NumLayers, StartRow); NewSoil.Water.LL15 = GetDoubleValues(Table, "LL15 (mm/mm)", NumLayers, StartRow); NewSoil.Water.LL15Metadata = GetCodeValues(Table, "LL15Code", NumLayers, StartRow); NewSoil.Water.AirDry = GetDoubleValues(Table, "Airdry (mm/mm)", NumLayers, StartRow); NewSoil.Water.AirDryMetadata = GetCodeValues(Table, "AirdryCode", NumLayers, StartRow); NewSoil.SoilWater = new SoilWater(); NewSoil.SoilWater.Thickness = NewSoil.Water.Thickness; NewSoil.SoilWater.SummerU = GetDoubleValue(Table, StartRow, "SummerU"); NewSoil.SoilWater.SummerCona = GetDoubleValue(Table, StartRow, "SummerCona"); NewSoil.SoilWater.WinterU = GetDoubleValue(Table, StartRow, "WinterU"); NewSoil.SoilWater.WinterCona = GetDoubleValue(Table, StartRow, "WinterCona"); NewSoil.SoilWater.SummerDate = GetStringValue(Table, StartRow, "SummerDate"); NewSoil.SoilWater.WinterDate = GetStringValue(Table, StartRow, "WinterDate"); NewSoil.SoilWater.Salb = GetDoubleValue(Table, StartRow, "Salb"); NewSoil.SoilWater.DiffusConst = GetDoubleValue(Table, StartRow, "DiffusConst"); NewSoil.SoilWater.DiffusSlope = GetDoubleValue(Table, StartRow, "DiffusSlope"); NewSoil.SoilWater.CN2Bare = GetDoubleValue(Table, StartRow, "Cn2Bare"); NewSoil.SoilWater.CNRed = GetDoubleValue(Table, StartRow, "CnRed"); NewSoil.SoilWater.CNCov = GetDoubleValue(Table, StartRow, "CnCov"); if (Table.Columns.Contains("ThicknessChem (mm)")) { NewSoil.SoilOrganicMatter.Thickness = MathUtility.RemoveMissingValuesFromBottom(GetDoubleValues(Table, "ThicknessChem (mm)", NumRows, StartRow)); } else { NewSoil.SoilOrganicMatter.Thickness = NewSoil.Water.Thickness; } int NumChemLayers = NewSoil.SoilOrganicMatter.Thickness.Length; NewSoil.SoilOrganicMatter.RootCN = GetDoubleValue(Table, StartRow, "RootCn"); NewSoil.SoilOrganicMatter.RootWt = GetDoubleValue(Table, StartRow, "RootWt"); NewSoil.SoilOrganicMatter.SoilCN = GetDoubleValue(Table, StartRow, "SoilCN"); NewSoil.SoilOrganicMatter.EnrACoeff = GetDoubleValue(Table, StartRow, "EnrACoeff"); NewSoil.SoilOrganicMatter.EnrBCoeff = GetDoubleValue(Table, StartRow, "EnrBCoeff"); NewSoil.SoilWater.SWCON = GetDoubleValues(Table, "SWCON (0-1)", NumLayers, StartRow); NewSoil.SoilWater.MWCON = GetDoubleValues(Table, "MWCON (0-1)", NumLayers, StartRow); NewSoil.SoilOrganicMatter.FBiom = GetDoubleValues(Table, "FBIOM (0-1)", NumChemLayers, StartRow); NewSoil.SoilOrganicMatter.FInert = GetDoubleValues(Table, "FINERT (0-1)", NumChemLayers, StartRow); NewSoil.Water.KS = GetDoubleValues(Table, "KS (mm/day)", NumLayers, StartRow); NewSoil.SoilOrganicMatter.OC = GetDoubleValues(Table, "OC", NumChemLayers, StartRow); NewSoil.SoilOrganicMatter.OCMetadata = GetCodeValues(Table, "OCCode", NumChemLayers, StartRow); NewSoil.SoilOrganicMatter.OCUnits = GetOCUnits(Table, StartRow); NewSoil.Analysis.Thickness = NewSoil.SoilOrganicMatter.Thickness; NewSoil.Analysis.EC = GetDoubleValues(Table, "EC (1:5 dS/m)", NumChemLayers, StartRow); NewSoil.Analysis.ECMetadata = GetCodeValues(Table, "ECCode", NumChemLayers, StartRow); NewSoil.Analysis.PH = GetDoubleValues(Table, "PH", NumChemLayers, StartRow); NewSoil.Analysis.PHMetadata = GetCodeValues(Table, "PHCode", NumChemLayers, StartRow); NewSoil.Analysis.PHUnits = GetPHUnits(Table, StartRow); NewSoil.Analysis.CL = GetDoubleValues(Table, "CL (mg/kg)", NumChemLayers, StartRow); NewSoil.Analysis.CLMetadata = GetCodeValues(Table, "CLCode", NumChemLayers, StartRow); NewSoil.Analysis.Boron = GetDoubleValues(Table, "Boron (Hot water mg/kg)", NumChemLayers, StartRow); NewSoil.Analysis.BoronMetadata = GetCodeValues(Table, "BoronCode", NumChemLayers, StartRow); NewSoil.Analysis.CEC = GetDoubleValues(Table, "CEC (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.CECMetadata = GetCodeValues(Table, "CECCode", NumChemLayers, StartRow); NewSoil.Analysis.Ca = GetDoubleValues(Table, "Ca (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.CaMetadata = GetCodeValues(Table, "CaCode", NumChemLayers, StartRow); NewSoil.Analysis.Mg = GetDoubleValues(Table, "Mg (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.MgMetadata = GetCodeValues(Table, "MgCode", NumChemLayers, StartRow); NewSoil.Analysis.Na = GetDoubleValues(Table, "Na (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.NaMetadata = GetCodeValues(Table, "NaCode", NumChemLayers, StartRow); NewSoil.Analysis.K = GetDoubleValues(Table, "K (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.KMetadata = GetCodeValues(Table, "KCode", NumChemLayers, StartRow); NewSoil.Analysis.ESP = GetDoubleValues(Table, "ESP (%)", NumChemLayers, StartRow); NewSoil.Analysis.ESPMetadata = GetCodeValues(Table, "ESPCode", NumChemLayers, StartRow); NewSoil.Analysis.Mn = GetDoubleValues(Table, "Mn (mg/kg)", NumChemLayers, StartRow); NewSoil.Analysis.MnMetadata = GetCodeValues(Table, "MnCode", NumChemLayers, StartRow); NewSoil.Analysis.Al = GetDoubleValues(Table, "Al (cmol+/kg)", NumChemLayers, StartRow); NewSoil.Analysis.AlMetadata = GetCodeValues(Table, "AlCode", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSand = GetDoubleValues(Table, "ParticleSizeSand (%)", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSandMetadata = GetCodeValues(Table, "ParticleSizeSandCode", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSilt = GetDoubleValues(Table, "ParticleSizeSilt (%)", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeSiltMetadata = GetCodeValues(Table, "ParticleSizeSiltCode", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeClay = GetDoubleValues(Table, "ParticleSizeClay (%)", NumChemLayers, StartRow); NewSoil.Analysis.ParticleSizeClayMetadata = GetCodeValues(Table, "ParticleSizeClayCode", NumChemLayers, StartRow); // crops foreach (DataColumn Col in Table.Columns) { if (Col.ColumnName.ToLower().Contains(" ll")) { string[] NameBits = Col.ColumnName.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (NameBits.Length == 3) { string CropName = NameBits[0]; SoilCrop NewCrop = new SoilCrop(); NewCrop.Name = CropName; NewCrop.Thickness = NewSoil.Water.Thickness; NewCrop.LL = GetDoubleValues(Table, CropName + " ll (mm/mm)", NumLayers, StartRow); NewCrop.LLMetadata = GetCodeValues(Table, CropName + " llCode", NumLayers, StartRow); NewCrop.KL = GetDoubleValues(Table, CropName + " kl (/day)", NumLayers, StartRow); NewCrop.XF = GetDoubleValues(Table, CropName + " xf (0-1)", NumLayers, StartRow); if (MathUtility.ValuesInArray(NewCrop.LL) || MathUtility.ValuesInArray(NewCrop.KL)) { NewSoil.Water.Crops.Add(NewCrop); } } } } StartRow += NumRows; if (Notifier != null) { Notifier.Invoke(Convert.ToInt32(StartRow * 100.0 / Table.Rows.Count)); } counter++; if (counter == 50) { GC.Collect(); counter = 0; } } return(Soils.ToArray()); }
public override void OnSave() { // -------------------------------------------------- // Save the variable grid back to the selected data. // -------------------------------------------------- if (Grid.EditingControl != null) // Save any current edits { Grid.EndEdit(); } // Work out the property type from the currently selected data type by removing the last character. // e.g. if current data type is 'variables' then property type is 'variable' string PropertyType = XmlHelper.Type(Data); if (PropertyType.ToLower() == "tracker") { PropertyType = "variables"; } PropertyType = PropertyType.Remove(PropertyType.Length - 1); // Turn from plural to singular. string[] VariableNames = DataTableUtility.GetColumnAsStrings(Grid.DataSourceTable, Grid.DataSourceTable.Columns[0].ColumnName); Data.RemoveAll(); string DataName = XmlHelper.Name(Data); XmlHelper.SetName(Data, DataName); foreach (string VariableName in VariableNames) { if (!string.IsNullOrEmpty(VariableName)) { XmlNode Variable = Data.AppendChild(Data.OwnerDocument.CreateElement(PropertyType)); Variable.InnerText = VariableName; } } XmlNode Constants = XmlHelper.Find(Data, "constants"); if ((Constants != null)) { Data.RemoveChild(Constants); } XmlNode ConstantsNode = null; foreach (string Line in ConstantsBox.Lines) { int PosEquals = Line.IndexOf("="); if (PosEquals != -1) { string ConstantName = Line.Substring(0, PosEquals).Trim(); string ConstantValue = Line.Substring(PosEquals + 1).Trim(); if ((ConstantName == "Title")) { MessageBox.Show("You cannot specify a title. It is set automatically to the name of the simulation", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if ((ConstantsNode == null)) { ConstantsNode = XmlHelper.Find(Data, "constants"); if ((ConstantsNode == null)) { ConstantsNode = Data.AppendChild(Data.OwnerDocument.CreateElement("constants")); } } XmlNode ConstantNode = Data.OwnerDocument.CreateElement("constant"); XmlHelper.SetName(ConstantNode, ConstantName); ConstantNode.InnerText = ConstantValue; ConstantsNode.AppendChild(ConstantNode); } } } }
/// <summary> /// Refresh the chart from data in the specified datasource. /// </summary> public void Populate(DataTable DataSource, string ChartType, Soil Soil) { this.Soil = Soil; this.Table = DataSource; DataSource.TableName = ChartType; Chart.Axes.Left.Automatic = true; Chart.Axes.Top.Automatic = true; Chart.Axes.Right.Automatic = true; Chart.Axes.Bottom.Automatic = true; //Chart.Series.Clear(); // Try and load an appropriate template. if (Directory.Exists(Path.Combine(Configuration.ApsimDirectory(), "UserInterface"))) { FileName = Path.Combine(Configuration.ApsimDirectory(), "UserInterface", ChartType + ".xml"); } else { FileName = Path.Combine(Configuration.ApsimDirectory(), ChartType + ".xml"); } XmlDocument Doc = new XmlDocument(); if (File.Exists(FileName)) { Doc.Load(FileName); Data = Doc.DocumentElement; } else { Data = null; } // Get the base chart to do it's thing. base.OnRefresh(); // Make sure there is a DepthMidPoints column if (DataSource.Columns.IndexOf("DepthMidPoints (mm)") == -1) { try { string[] Depths = DataTableUtility.GetColumnAsStrings(DataSource, "Depth (cm)"); double[] Thickness = Soil.ToThickness(Depths); double[] DepthMidPoints = Soil.ToMidPoints(Thickness); DataTableUtility.AddColumn(DataSource, "DepthMidPoints (mm)", DepthMidPoints); } catch (Exception e) { MessageBox.Show(e.Message); } } // Add in LL series and SW if it is present. foreach (DataColumn Column in DataSource.Columns) { if (Column.ColumnName.Contains(" LL") || Column.ColumnName.Contains("SW")) { Line Line = new Line(); Line.LinePen.Width = 2; AddSeries(DataSource, Column.ColumnName, Line); } } // Get our data. AddDataSource(DataSource); AdjustTopAxisTitle = false; // For some charts were we don't have a predefined chart XML file we need to set // up some default chart settings. Chart.Axes.Left.Inverted = true; // If there are no series then add some e.g. Analysis if (Chart.Series.Count == 0) { bool FirstSeries = true; foreach (DataColumn Column in DataSource.Columns) { if (Column.DataType == typeof(double) && !Column.ColumnName.Contains("Depth")) { string[] Values = DataTableUtility.GetColumnAsStrings(DataSource, Column.ColumnName); if (MathUtility.ValuesInArray(Values)) { Line Line = new Line(); Line.LinePen.Width = 2; AddSeries(DataSource, Column.ColumnName, Line); Line.Active = FirstSeries; FirstSeries = false; } } } AdjustTopAxisTitle = true; FormatTopAxis(); } // Now we can populate all series as we've created our series. PopulateSeries(); Chart.Refresh(); }
/// <summary> /// Populate all series with data. /// </summary> public void PopulateSeries() { bool LeftAxisUsed = false; bool RightAxisUsed = false; bool BottomAxisUsed = false; bool TopAxisUsed = false; int SeriesIndex = 1; foreach (Series S in Chart.Series) { if (S.HorizAxis == HorizontalAxis.Bottom) { BottomAxisUsed = true; } else { TopAxisUsed = true; } if (S.VertAxis == VerticalAxis.Left) { LeftAxisUsed = true; } else { RightAxisUsed = true; } // Read in XML about this series. XmlDocument Doc = new XmlDocument(); Doc.LoadXml(S.ValuesLists[0].DataMember); string DataSource = XmlHelper.Value(Doc.DocumentElement, "DataSource"); List <string> ColumnNames = new List <string>(); ColumnNames.Add(XmlHelper.Value(Doc.DocumentElement, "X")); ColumnNames.Add(XmlHelper.Value(Doc.DocumentElement, "Y")); ColumnNames.Add(XmlHelper.Value(Doc.DocumentElement, "Y2")); ColumnNames.Add(XmlHelper.Value(Doc.DocumentElement, "Y3")); ColumnNames.Add(XmlHelper.Value(Doc.DocumentElement, "Y4")); DataTable Table = GetDataSourceWithName(DataSource); for (int i = 0; i < S.ValuesLists.Count; i++) { S.ValuesLists[i].Clear(); if (Table != null && i < ColumnNames.Count) { string ColumnName = ColumnNames[i]; if (Table.Columns.Contains(ColumnName)) { if (i == 0 && Table.Columns[ColumnName].DataType == typeof(string)) { S.Labels.Clear(); S.Labels.AddRange(DataTableUtility.GetColumnAsStrings(Table, ColumnName)); } else if (Table.Columns[ColumnName].DataType == typeof(double) || Table.Columns[ColumnName].DataType == typeof(float)) { S.ValuesLists[i].Value = DataTableUtility.GetColumnAsDoubles(Table, ColumnName); S.ValuesLists[i].Count = S.ValuesLists[i].Value.Length; } else if (Table.Columns[ColumnName].DataType == typeof(DateTime)) { DateTime[] Dates = DataTableUtility.GetColumnAsDates(Table, ColumnName); double[] Values = new double[Dates.Length]; for (int j = 0; j < Values.Length; j++) { Values[j] = Dates[j].ToOADate(); } S.ValuesLists[i].Value = Values; S.ValuesLists[i].Count = S.ValuesLists[i].Value.Length; S.ValuesLists[i].DateTime = true; } } else { S.ValuesLists[i].Value = MathUtility.CreateArrayOfValues(SeriesIndex, Table.Rows.Count); S.ValuesLists[i].Count = S.ValuesLists[i].Value.Length; SeriesIndex++; } } } // Strip out missing values. StripOutMissingValues(S); Chart.Axes.Left.Visible = LeftAxisUsed; Chart.Axes.Right.Visible = RightAxisUsed; Chart.Axes.Top.Visible = TopAxisUsed; Chart.Axes.Bottom.Visible = BottomAxisUsed; } }