Wednesday, June 6, 2012

Stacked100ColumnSeries at run time

If you want to add SeriesDefenition of a Stacked100ColumnSeries its bit tricky. You can do it by writing code like the one I have written.

  private void GetSeries(IEnumerable enumrable, Stacked100ColumnSeries series)
        {
            var k = enumrable as ObservableCollection;
            var parsedData = CustIncomeGraph.ParseDataForStackGraph(k);
            //var series = new ObservableCollection();
            int i = 0;
            series.SeriesDefinitions.Clear();
            CustIncomeGraph.GetDistinctTraderName(k).ForEach(s =>
                {
                    SeriesDefinition def = new SeriesDefinition();
                    def.Title = s;
                    def.IndependentValuePath = "TimeFrame";
                    var binding1 = new Binding("TradersIncome");
                    binding1.Converter = new IncomeGraphConverter();
                    binding1.ConverterParameter = s;
                    def.DependentValueBinding = binding1;
                    def.ItemsSource = parsedData;
                    series.SeriesDefinitions.Add(def);
                    i++;
                });

            //return series;
        }

where CustIncomeGraph is an entity it could be any class as per your requirement.


 public class IncomeGraphConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return 0;
            var param = System.Convert.ToString(parameter);
            var val = value as Dictionary;
            return val.ContainsKey(param) ? val[param] : 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

This works for me. Comments and questions will be highly appreciated.

Regards
Vinod

No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog