public static string GetDataValue(object dataItem, string names) { if (dataItem == null) { return(string.Empty); } if (string.IsNullOrWhiteSpace(names)) { return(string.Empty); } string result = string.Empty; string[] keys = names.Split(','); foreach (string key in keys) { if (string.IsNullOrWhiteSpace(key)) { continue; } result += string.Format("{0},", BindingUtility.GetBindingValue(key.Trim(), dataItem, null)); } if (string.IsNullOrWhiteSpace(result)) { return(string.Empty); } else { return(result.TrimEnd(',')); } }
private void SetBinding() { if (_binding == null || this.DataSource == null) { return; } IEnumerable dataSource = this.DataSource as IEnumerable; if (dataSource == null) { return; } if (this.Type == ChartType.Pie) { foreach (var dataItem in dataSource) { this.Points.Add(new ChartPoint() { Title = BindingUtility.FormatBindingValue(_binding.TitleMember, dataItem), Value = Zongsoft.Common.Convert.ConvertValue <decimal>(BindingUtility.GetBindingValue(_binding.ValueMember, dataItem)), }); } } else { Dictionary <string, List <decimal> > lines = new Dictionary <string, List <decimal> >(StringComparer.OrdinalIgnoreCase); foreach (var dataItem in dataSource) { string key = BindingUtility.FormatBindingValue(_binding.TitleMember, dataItem); List <decimal> values; decimal v = Zongsoft.Common.Convert.ConvertValue <decimal>(BindingUtility.GetBindingValue(_binding.ValueMember, dataItem)); if (lines.TryGetValue(key, out values)) { values.Add(v); } else { values = new List <decimal>(); values.Add(v); lines[key] = values; } if (!string.IsNullOrWhiteSpace(_binding.SerieMember)) { string serie = BindingUtility.FormatBindingValue(_binding.SerieMember, dataItem); if (!this.Series.Contains(serie)) { this.Series.Add(new ChartSerie() { Name = serie, Title = serie, }); } } } foreach (var entry in lines) { this.Lines.Add(new ChartLine() { Name = entry.Key, Title = entry.Key, Values = entry.Value.ToArray(), }); } } }