protected override void GenerateChartData(Dictionary<DataTable, List<DescriptiveStatistics>> stratifiedFrequencyTables, Strata strata = null)
        {
            lock (syncLockData)
            {
                string second_y_var = string.Empty;

                if (GadgetOptions.InputVariableList.ContainsKey("second_y_var"))
                {
                    second_y_var = GadgetOptions.InputVariableList["second_y_var"];
                }

                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;
                    DataTable epiCurveTable = new DataTable("epiCurveTable");
                    epiCurveTable.Columns.Add(new DataColumn(table.Columns[0].ColumnName, typeof(string)));
                    epiCurveTable.Columns.Add(new DataColumn(table.Columns[1].ColumnName, typeof(double)));

                    DataColumn[] parentPrimaryKeyColumns = new DataColumn[1];
                    parentPrimaryKeyColumns[0] = epiCurveTable.Columns[0];
                    epiCurveTable.PrimaryKey = parentPrimaryKeyColumns;

                    int step = 1;
                    int.TryParse(GadgetOptions.InputVariableList["step"], out step);

                    string interval = "day";
                    if (GadgetOptions.InputVariableList.ContainsKey("interval"))
                    {
                        interval = GadgetOptions.InputVariableList["interval"];
                    }

                    switch (interval)
                    {
                        case "year":
                            CalculateByYear(table, epiCurveTable, step);
                            break;
                        case "minute":
                            CalculateByMinute(table, epiCurveTable, step);
                            break;
                        case "hour":
                            CalculateByHour(table, epiCurveTable, step);
                            break;
                        case "month":
                            CalculateByMonth(table, epiCurveTable, step);
                            break;
                        default:
                        case "day":
                            CalculateByDay(table, epiCurveTable, step);
                            break;
                    }

                    foreach (DataRow row in epiCurveTable.Rows)
                    {
                        XYColumnChartData chartData = new XYColumnChartData();
                        chartData.X = strataValue;
                        chartData.Y = (double)row[1];

                        chartData.S = row[0].ToString();

                        //Debug.Print(chartData.S + " : " + chartData.Y);

                        dataList.Add(chartData);
                    }
                }

                this.Dispatcher.BeginInvoke(new SetChartDataDelegate(SetChartData), dataList, strata);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        protected override void GenerateChartData(Dictionary<DataTable, List<DescriptiveStatistics>> stratifiedFrequencyTables, Strata strata = null)
        {
            lock (syncLockData)
            {
                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;

                    foreach (DataRow row in table.Rows)
                    {
                        XYColumnChartData chartData = new XYColumnChartData();
                        chartData.X = strataValue;
                        chartData.Y = (double)row[1];
                        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);
            }
        }
Esempio n. 4
0
        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:
                        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);
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 private bool ValueMissing(XYColumnChartData chartData)
 {
     return(chartData.S.ToString() == Config.Settings.RepresentationOfMissing);
 }
Esempio n. 7
0
        private bool OutsideLimits(XYColumnChartData chartData)
        {
            ColumnChartParameters chtParameters = (ColumnChartParameters)Parameters;

            return(OutsideLimits(chartData.S, chtParameters.XAxisStart, chtParameters.XAxisEnd));
        }
        //protected void cmbXAxisLabelType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    TextBox txtXAxisLabelValue = this.FindName("txtXAxisLabelValue") as TextBox;
        //    ComboBox cmbXAxisLabelType = this.FindName("cmbXAxisLabelType") as ComboBox;
        //    if (LoadingCombos || txtXAxisLabelValue == null) return;
        //    SetXAxisLabelControls();
        //}
        //protected void SetXAxisLabelControls()
        //{
        //    TextBox txtXAxisLabelValue = this.FindName("txtXAxisLabelValue") as TextBox;
        //    ComboBox cmbXAxisLabelType = this.FindName("cmbXAxisLabelType") as ComboBox;
        //    switch (cmbXAxisLabelType.SelectedIndex)
        //    {
        //        case 3:
        //            txtXAxisLabelValue.IsEnabled = true;
        //            break;
        //        case 0:
        //        case 1:
        //        case 2:
        //            txtXAxisLabelValue.IsEnabled = false;
        //            txtXAxisLabelValue.Text = string.Empty;
        //            break;
        //    }
        //}
        //protected override void CopyToClipboard()
        //{
        //    object el = this.FindName("panelMain");
        //    if (el is StackPanel)
        //    {
        //        StringBuilder sb = new StringBuilder();
        //        foreach(UIElement element in (el as StackPanel).Children)
        //        {
        //            if (element is Controls.Charting.IChart)
        //            {
        //                sb.AppendLine((element as Controls.Charting.IChart).SendDataToString());
        //            }
        //        }
        //        Clipboard.Clear();
        //        Clipboard.SetText(sb.ToString());
        //    }
        //}
        //protected virtual void cmbField_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    if(sender is ComboBox)
        //    {
        //        ComboBox cmbField = sender as ComboBox;
        //        CheckBox checkboxAllValues = null;
        //        CheckBox checkboxCommentLegalLabels = null;
        //        object element = this.FindName("checkboxAllValues");
        //        if(element != null && element is CheckBox)
        //        {
        //            checkboxAllValues = element as CheckBox;
        //        }
        //        element = this.FindName("checkboxCommentLegalLabels");
        //        if(element != null && element is CheckBox)
        //        {
        //            checkboxCommentLegalLabels = element as CheckBox;
        //        }
        //        if (cmbField.SelectedIndex >= 0)
        //        {
        //            Field field = DashboardHelper.GetAssociatedField(cmbField.SelectedItem.ToString());
        //            if (field != null && field is RenderableField)
        //            {
        //                FieldFlags flags = SetFieldFlags(field as RenderableField);
        //                if (checkboxAllValues != null)
        //                {
        //                    if (flags.IsDropDownListField || flags.IsRecodedField)
        //                    {
        //                        checkboxAllValues.IsEnabled = true;
        //                    }
        //                    else
        //                    {
        //                        checkboxAllValues.IsEnabled = false;
        //                        checkboxAllValues.IsChecked = false;
        //                    }
        //                }
        //                if (checkboxCommentLegalLabels != null)
        //                {
        //                    if (flags.IsCommentLegalField || flags.IsOptionField)
        //                    {
        //                        checkboxCommentLegalLabels.IsEnabled = true;
        //                    }
        //                    else
        //                    {
        //                        checkboxCommentLegalLabels.IsEnabled = false;
        //                        checkboxCommentLegalLabels.IsChecked = false;
        //                    }
        //                    if (!flags.IsCommentLegalField && !flags.IsOptionField)
        //                    {
        //                        checkboxCommentLegalLabels.IsChecked = flags.IsCommentLegalField;
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}
        //protected void chart_MouseLeave(object sender, MouseEventArgs e)
        //{
        //    //SelectedChart = null;
        //}
        //protected void chart_MouseEnter(object sender, MouseEventArgs e)
        //{
        //    //object element = this.FindName("gadgetContextMenu");
        //    //if ((element is ContextMenu) && !(element as ContextMenu).IsOpen)
        //    //{
        //    //    SelectedChart = sender as Controls.Charting.IChart;
        //    //}
        //    //else
        //    //{
        //    //    SelectedChart = null;
        //    //}
        //}
        ///// <summary>
        ///// Converts the gadget's output to Html
        ///// </summary>
        ///// <returns></returns>
        //public override string ToHTML(string htmlFileName = "", int count = 0)
        //{
        //    TextBox txtChartTitle = null;
        //    StackPanel panelMain = null;
        //    object el = FindName("txtChartTitle");
        //    if (el is TextBox)
        //    {
        //        txtChartTitle = el as TextBox;
        //    }
        //    el = FindName("panelMain");
        //    if (el is StackPanel)
        //    {
        //        panelMain = el as StackPanel;
        //    }
        //    if (txtChartTitle == null || panelMain == null) return string.Empty;
        //    StringBuilder sb = new StringBuilder();
        //    sb.AppendLine("<h2>" + txtChartTitle.Text + "</h2>");
        //    foreach (UIElement element in panelMain.Children)
        //    {
        //        if (element is EpiDashboard.Controls.Charting.IChart)
        //        {
        //            sb.AppendLine(((EpiDashboard.Controls.Charting.IChart)element).ToHTML(htmlFileName, count, true, false));
        //        }
        //    }
        //    return sb.ToString();
        //}
        //protected enum Y2Type
        //{
        //    None,
        //    SingleField,
        //    RatePer100kPop,
        //    CumulativePercent
        //}
        protected virtual bool GenerateColumnChartData(Dictionary<DataTable, List<DescriptiveStatistics>> stratifiedFrequencyTables, Strata strata = null)
        {
            lock (syncLockData)
            {
                ColumnChartParameters chtParameters = (ColumnChartParameters)Parameters;

                string second_y_var = string.Empty;

                Y2Type y2type = Y2Type.None;

                //CORRECTED BELOW FOR COLUMN_CHART_PARAMETERS
                //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;
                //}

                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[GadgetOptions.MainVariableName].ToString()) && (y2type == Y2Type.CumulativePercent || dRow[second_y_var] != DBNull.Value))
                                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];
                        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);
            }

            return true;
        }
Esempio n. 9
0
        protected virtual void GenerateChartData(Dictionary<DataTable, List<DescriptiveStatistics>> stratifiedFrequencyTables, Strata strata = null)
        {
            lock (syncLockData)
            {
                string second_y_var = string.Empty;

                Y2Type y2type = Y2Type.None;

                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;
                }

                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()) && (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);
                    }

                    var query = from chartData in dataList
                                orderby chartData.S ascending
                                select chartData;

                    XYColumnChartData firstObj = query.First();
                    XYColumnChartData lastObj = query.Last();

                    if (XAxisStart.HasValue && XAxisStart.Value >= 0 &&
                        (table.Columns[0].DataType.ToString().Equals("System.Single") ||
                        table.Columns[0].DataType.ToString().Equals("System.Double") ||
                        table.Columns[0].DataType.ToString().Equals("System.Decimal")))
                    {
                        if (Convert.ToDouble(lastObj.S) > XAxisStart.Value)
                        {
                            XYColumnChartData fillerFirst = new XYColumnChartData();
                            fillerFirst.Y = 0;
                            fillerFirst.X = strataValue;
                            fillerFirst.S = XAxisStart.Value;
                            dataList.Add(fillerFirst);
                        }
                    }

                    if (XAxisEnd.HasValue && XAxisEnd.Value >= 0 &&
                        (table.Columns[0].DataType.ToString().Equals("System.Single") ||
                        table.Columns[0].DataType.ToString().Equals("System.Double") ||
                        table.Columns[0].DataType.ToString().Equals("System.Decimal")))
                    {
                        if (Convert.ToDouble(lastObj.S) < XAxisEnd.Value)
                        {
                            XYColumnChartData fillerLast = new XYColumnChartData();
                            fillerLast.Y = 0;
                            fillerLast.X = strataValue;
                            fillerLast.S = XAxisEnd.Value;
                            dataList.Add(fillerLast);
                        }
                    }
                }

                this.Dispatcher.BeginInvoke(new SetChartDataDelegate(SetChartData), dataList, strata);
            }
        }