private List <DxSeriesPoints> CreateSeries(DataTable dt, string xvar, string colorvar, string panelvar, List <Color> colors, List <string> color_levels) { List <string> groupvars = new List <string>(); int panename_idx = -1; if (panelvar == "none" & colorvar != "none") { groupvars = new List <string>() { xvar, colorvar }; panename_idx = -1; } else if (panelvar != "none" & colorvar == "none") { groupvars = new List <string>() { xvar, panelvar }; panename_idx = 1; } else if (panelvar != "none" & colorvar != "none") { groupvars = new List <string>() { xvar, colorvar, panelvar }; panename_idx = 2; } List <DxSeriesPoints> list_series = new List <DxSeriesPoints>(); try { // from: http://www.scriptscoop.net/t/7516b362c821/c-c-linq-how-to-build-group-by-clause-dynamically.html IEnumerable <string> columnsToGroupBy = groupvars; var groups = dt.AsEnumerable() .GroupBy(r => new NTuple <object>(from column in columnsToGroupBy select r[column])); int n_groups = groups.Count(); foreach (var group in groups) { DataTable dtSub = group.CopyToDataTable(); //List<string> keyvalues = group.Key.Values[0].ToString(); List <string> keyvalues = new List <string>(); foreach (var s in group.Key.Values) { keyvalues.Add(s.ToString()); } DxSeriesPoints pts = new DxSeriesPoints(dtSub, xvar, "M", colorvar, colors, color_levels); pts.label = String.Join(" : ", keyvalues); pts.panename = (panename_idx >= 0) ? keyvalues[panename_idx] : "none"; list_series.Add(pts); } } catch (Exception ex) { throw new Exception("ERROR! qryGroupBy Msg:" + ex.Message + "............." + ex.StackTrace.ToString()); } return(list_series); }
//public ScatterplotSeries(DataTable dt, string xvar, string yvar, string colorvar, string panelvar, List<Color> colors, List<string> color_levels) //{ // CreateSeries(dt, xvar, yvar, colorvar, panelvar, colors, color_levels); //} private void CreateSeries(DataTable dt, DxScatterplotSettings settings) //, string xvar, string yvar, string colorvar, string panelvar, List<Color> colors, List<string> color_levels) { _list_corrs = new List <Corrs>(); _list_dxseriespoints = new List <DxSeriesPoints>(); //, settings.xaxisvar, settings.yaxisvar, settings.colorvar, settings.panevar, settings.colors, settings.colorLevels); List <string> groupvars = new List <string>(); int panename_idx = -1; if (settings.panevar == "none" & settings.colorvar != "none") //This is different than for Bar { groupvars = new List <string>() { settings.colorvar }; panename_idx = 0; } else if (settings.panevar != "none" & settings.colorvar == "none") { groupvars = new List <string>() { settings.panevar }; panename_idx = 0; } else if (settings.panevar != "none" & settings.colorvar != "none") { groupvars = new List <string>() { settings.panevar, settings.colorvar }; panename_idx = 0; } groupvars = groupvars.Distinct().ToList(); List <DxSeriesPoints> list_series = new List <DxSeriesPoints>(); try { // from: http://www.scriptscoop.net/t/7516b362c821/c-c-linq-how-to-build-group-by-clause-dynamically.html IEnumerable <string> columnsToGroupBy = groupvars; var groups = dt.AsEnumerable() .GroupBy(r => new NTuple <object>(from column in columnsToGroupBy select r[column])); int n_groups = groups.Count(); foreach (var group in groups) { DataTable dtSub = group.CopyToDataTable(); Corrs tmpcorrs = new Corrs(dtSub, settings.xaxisvar, settings.yaxisvar, 2); _list_corrs.Add(tmpcorrs); //List<string> keyvalues = group.Key.Values[0].ToString(); List <string> keyvalues = new List <string>(); foreach (var s in group.Key.Values) { keyvalues.Add(s.ToString()); } DxSeriesPoints pts = new DxSeriesPoints(dtSub, settings.xaxisvar, settings.yaxisvar, settings.colorvar, settings.colors, settings.colorLevels); pts.label = String.Join(" : ", keyvalues); pts.panename = (panename_idx >= 0) ? keyvalues[panename_idx] : "none"; _list_dxseriespoints.Add(pts); } } catch (Exception ex) { throw new Exception("ERROR! qryGroupBy Msg:" + ex.Message + "............." + ex.StackTrace.ToString()); } //return list_series; }