protected virtual void GenerateChartData(Dictionary <DataTable, List <DescriptiveStatistics> > stratifiedFrequencyTables, Strata strata = null) { lock (syncLockData) { string second_y_var = string.Empty; Y2Type y2type = Y2Type.None; ///ToDo: Remove GadgetOptions code when Parameters obj fully implemented. ////////////////////////////////////// //if (GadgetOptions.InputVariableList.ContainsKey("second_y_var")) //{ // second_y_var = GadgetOptions.InputVariableList["second_y_var"]; //} //if (GadgetOptions.InputVariableList.ContainsKey("second_y_var_type") && GadgetOptions.InputVariableList["second_y_var_type"].Equals("rate_per_100k")) //{ // y2type = Y2Type.RatePer100kPop; //} //else if (GadgetOptions.InputVariableList.ContainsKey("second_y_var_type") && GadgetOptions.InputVariableList["second_y_var_type"].Equals("cumulative_percent")) //{ // y2type = Y2Type.CumulativePercent; //} /////////////////////////////////////////////////////////////////////////////////////////////////////////////// switch ((Parameters as IChartGadgetParameters).Y2AxisType) { case 1: y2type = Y2Type.SingleField; //EI-430 if (Parameters.ColumnNames.Count > 1 && !String.IsNullOrEmpty(Parameters.ColumnNames[1])) { second_y_var = Parameters.ColumnNames[1]; } break; case 2: y2type = Y2Type.RatePer100kPop; if (Parameters.ColumnNames.Count > 1 && !String.IsNullOrEmpty(Parameters.ColumnNames[1])) { second_y_var = Parameters.ColumnNames[1]; } break; case 3: y2type = Y2Type.CumulativePercent; break; } List <XYColumnChartData> dataList = new List <XYColumnChartData>(); foreach (KeyValuePair <DataTable, List <DescriptiveStatistics> > tableKvp in stratifiedFrequencyTables) { double count = 0; foreach (DescriptiveStatistics ds in tableKvp.Value) { count = count + ds.observations; } string strataValue = tableKvp.Key.TableName; DataTable table = tableKvp.Key; double cumulative_percent = 0; foreach (DataRow row in table.Rows) { XYColumnChartData chartData = new XYColumnChartData(); chartData.X = strataValue; chartData.Y = (double)row[1]; if (y2type != Y2Type.None) { foreach (DataRow dRow in DashboardHelper.DataSet.Tables[0].Rows) { //if (((row[0].ToString().Equals(dRow[GadgetOptions.MainVariableName].ToString()))||(row[0].ToString().Equals(dRow[Parameters.ColumnNames[0]].ToString()))) && (y2type == Y2Type.CumulativePercent || dRow[second_y_var] != DBNull.Value)) if ((row[0].ToString().Equals(dRow[Parameters.ColumnNames[0]].ToString())) && (y2type == Y2Type.CumulativePercent || dRow[second_y_var] != DBNull.Value)) { if (y2type == Y2Type.RatePer100kPop) { chartData.Y2 = chartData.Y / (Convert.ToDouble(dRow[second_y_var]) / 100000); } else if (y2type == Y2Type.CumulativePercent) { chartData.Y2 = cumulative_percent + (chartData.Y / count); cumulative_percent = chartData.Y2.Value; } else { chartData.Y2 = Convert.ToDouble(dRow[second_y_var]); } break; } } } else if (y2type == Y2Type.CumulativePercent) { foreach (DataRow dRow in DashboardHelper.DataSet.Tables[0].Rows) { } } chartData.S = row[0]; if (chartData.S == null || string.IsNullOrEmpty(chartData.S.ToString().Trim())) { chartData.S = Config.Settings.RepresentationOfMissing; } dataList.Add(chartData); } } this.Dispatcher.BeginInvoke(new SetChartDataDelegate(SetChartData), dataList, strata); } }
protected virtual bool GenerateColumnChartData(Dictionary <DataTable, List <DescriptiveStatistics> > stratifiedFrequencyTables, Strata strata = null) { int missingValueCount = 0; lock (syncLockData) { ColumnChartParameters chtParameters = (ColumnChartParameters)Parameters; string second_y_var = string.Empty; Y2Type y2type = Y2Type.None; if (chtParameters.ColumnNames.Count > 1 && !String.IsNullOrEmpty(chtParameters.ColumnNames[1])) { second_y_var = chtParameters.ColumnNames[1]; } if (chtParameters.Y2AxisType == 2) { y2type = Y2Type.RatePer100kPop; } else if (chtParameters.Y2AxisType == 3) { y2type = Y2Type.CumulativePercent; } List <XYColumnChartData> dataList = new List <XYColumnChartData>(); foreach (KeyValuePair <DataTable, List <DescriptiveStatistics> > tableKvp in stratifiedFrequencyTables) { double count = 0; foreach (DescriptiveStatistics ds in tableKvp.Value) { count = count + ds.observations; } // If there is only one table and the total for that table is zero, then no data can be displayed and thus no chart can be generated. // Show a message to the user to this effect so they don't wonder why they're seeing a blank gadget. // Commented out for now because of scenarios where the "One chart for each value of" option is used, and we're unsure how to handle // showing this message in that case. //if (count == 0 && stratifiedFrequencyTables.Count == 1) //{ // this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), DashboardSharedStrings.GADGET_MSG_NO_DATA); // return false; //} string strataValue = tableKvp.Key.TableName; DataTable table = tableKvp.Key; double cumulative_percent = 0; foreach (DataRow row in table.Rows) { XYColumnChartData chartData = new XYColumnChartData(); chartData.X = strataValue; chartData.Y = (double)row[1]; if (y2type != Y2Type.None) { foreach (DataRow dRow in DashboardHelper.DataSet.Tables[0].Rows) { if (row[0].ToString().Equals(dRow[chtParameters.ColumnNames[0]].ToString()) && (y2type == Y2Type.CumulativePercent || dRow[second_y_var] != DBNull.Value)) { if (y2type == Y2Type.RatePer100kPop) { chartData.Y2 = chartData.Y / (Convert.ToDouble(dRow[second_y_var]) / 100000); } else if (y2type == Y2Type.CumulativePercent) { chartData.Y2 = cumulative_percent + (chartData.Y / count); cumulative_percent = chartData.Y2.Value; } else { chartData.Y2 = Convert.ToDouble(dRow[second_y_var]); } break; } } } else if (y2type == Y2Type.CumulativePercent) { foreach (DataRow dRow in DashboardHelper.DataSet.Tables[0].Rows) { } } chartData.S = row[0]; string valueString = chartData.S.ToString().Trim(); if (chartData.S == null || string.IsNullOrEmpty(valueString)) { chartData.S = Config.Settings.RepresentationOfMissing; missingValueCount++; } dataList.Add(chartData); } dataList.RemoveAll(ValueMissing); dataList.RemoveAll(OutsideLimits); if (dataList.Count > 0) { if (dataList[0].S.GetType() != typeof(String)) { dataList.Sort(new ChartDataComparer()); } else if (chtParameters.SortStringValues) { dataList.Sort(new ChartDataComparer()); } } } this.Dispatcher.BeginInvoke(new SetChartDataDelegate(SetChartData), dataList, strata); } return(true); }