//public ColumnChartSettings ColumnChartSettings { get; set; } public ColumnChart(DashboardHelper dashboardHelper, ColumnChartParameters parameters, List <XYColumnChartData> dataList) { InitializeComponent(); //this.Settings = settings; //this.ColumnChartSettings = settings; ColumnChartParameters = parameters; this.DashboardHelper = dashboardHelper; SetChartProperties(); SetChartData(dataList); xyChart.Legend.BorderBrush = Brushes.Gray; }
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); }
private bool OutsideLimits(XYColumnChartData chartData) { ColumnChartParameters chtParameters = (ColumnChartParameters)Parameters; return(OutsideLimits(chartData.S, chtParameters.XAxisStart, chtParameters.XAxisEnd)); }