/// <summary> /// Function that is called by the Call back function when the Property Bar Color / ZColorValues changes. /// This function converts the string input of Bar color values to an array of Color Values. /// </summary> /// <param name="currentObject"></param> private static void UpdateZColorValues(WPF3DChart currentObject) { try { // First let's split the Input Colors to string array. string[] ZValueColorStrings = currentObject.ZValuesColor.Split(",".ToCharArray(), MAX_INPUT_EXPECTED); // If there are no Z axis Items, then there is no point in computing the Colors. if (currentObject.ZItems == null || currentObject.ZItems.Length == 0) return; // Initialize an array of colors to hold the Z Values currentObject.ZPlaneColors = new Color[currentObject.ZItems.Length]; int Counter = 0; // Fill in the Color values to the Array foreach (string zValueColorItem in ZValueColorStrings) { // Trim the string colors as user input may contain spaces string trimmedzValueColorItem = zValueColorItem.Trim(); // This function ColorFromString returns Media Color from the string value. currentObject.ZPlaneColors[Counter] = currentObject.ColorFromString(trimmedzValueColorItem); Counter++; // If the array is full, we need no more color values. if (Counter >= currentObject.ZItems.Length) break; } // In case, if the user has not specified enough colors, we fill with default color while (Counter < currentObject.ZItems.Length) { currentObject.ZPlaneColors[Counter] = currentObject.ColorFromString(DEFAULT_COLOR); Counter++; } } catch { // If there's an exception, then exit gracefully showing error to the user MessageBox.Show("Error in Color values input. Correct it and try again"); } }
/// <summary> /// This method is called by the callback function to update the Y values array in /// the 3D bar chart graph /// </summary> /// <param name="currentObject"></param> private static void UpdateYValues(WPF3DChart currentObject) { try { // Create a string array from the User input string[] YIemsArray = currentObject.YValuesInput.Split(",".ToCharArray(), MAX_INPUT_EXPECTED); // If there are no Z input values, there is no point in computing the bar length using Y values. if (currentObject.ZValuesInput == null || currentObject.XValuesInput == null || currentObject.ZValuesInput.Length * currentObject.XValuesInput.Length == 0) return; // Initialize the array with number of expected Y values. This is because the user might have // given more values or less values. currentObject.YItems = new int[currentObject.ZValuesInput.Length * currentObject.XValuesInput.Length]; int Counter = 0; // Fill in the array based on user input foreach (string yItemInArray in YIemsArray) { string yItem = yItemInArray.Trim(); try { currentObject.YItems[Counter] = int.Parse(yItem); } catch { // If the user input is wrong, fill that value to be 0. currentObject.YItems[Counter] = int.Parse("0"); } Counter++; } // If the user has less Y values inputs, then fill the empty with 0 values. while (Counter < currentObject.ZValuesInput.Length * currentObject.XValuesInput.Length) { currentObject.YItems[Counter] = 0; Counter++; } } catch { // If there's an exception, then exit gracefully showing error to the user MessageBox.Show("错误的图表值输入!"); } }