コード例 #1
0
ファイル: ChartBase.cs プロジェクト: yangdaichun/ZHXY.ZSXT
        private void UpdateGroupedSeries()
        {            
            List<DataPointGroup> result = new List<DataPointGroup>();
            try
            {
                ///sammle erst alle Gruppen zusammen
                foreach (ChartSeries initialSeries in this.Series)
                {
                    foreach (var seriesItem in initialSeries.Items)
                    {
                        string seriesItemCaption = GetPropertyValue(seriesItem, initialSeries.DisplayMember); //Security
                        DataPointGroup dataPointGroup = result.Where(group => group.Caption == seriesItemCaption).FirstOrDefault();
                        if (dataPointGroup == null)
                        {
                            dataPointGroup = new DataPointGroup();
                            dataPointGroup.Caption = seriesItemCaption;
                            dataPointGroup.PropertyChanged += dataPointGroup_PropertyChanged;
                            result.Add(dataPointGroup);

                            var groupBinding = new Binding();
                            groupBinding.Source = this;
                            groupBinding.Mode = BindingMode.TwoWay;
                            groupBinding.Path = new PropertyPath("SelectedItem");
                            BindingOperations.SetBinding(dataPointGroup, DataPointGroup.SelectedItemProperty, groupBinding);

                            int seriesIndex = 0;
                            foreach (ChartSeries allSeries in this.Series)
                            {
                                DataPoint datapoint = new DataPoint();
                                datapoint.SeriesCaption = allSeries.Caption;
                                datapoint.ValueMember = allSeries.ValueMember;
                                datapoint.DisplayMember = allSeries.DisplayMember;
                                datapoint.ItemBrush = GetItemBrush(seriesIndex);
                                datapoint.PropertyChanged += groupdItem_PropertyChanged;

                                //Sende an Datapoints the maximalvalue des Charts mit (wichtig in clustered Column chart)
                                var maxDataPointValueBinding = new Binding();
                                maxDataPointValueBinding.Source = this;
                                maxDataPointValueBinding.Mode = BindingMode.OneWay;
                                maxDataPointValueBinding.Path = new PropertyPath("MaxDataPointValue");
                                BindingOperations.SetBinding(datapoint, DataPoint.MaxDataPointValueProperty, maxDataPointValueBinding);

                                //Sende den Datapoints the höchste Summe einer DataPointGroup mit (wichtig für stacked chart)
                                var maxDataPointGroupSumBinding = new Binding();
                                maxDataPointGroupSumBinding.Source = this;
                                maxDataPointGroupSumBinding.Mode = BindingMode.OneWay;
                                maxDataPointGroupSumBinding.Path = new PropertyPath("MaxDataPointGroupSum");
                                BindingOperations.SetBinding(datapoint, DataPoint.MaxDataPointGroupSumProperty, maxDataPointGroupSumBinding);

                                //Sende den Datapoint die Summe seiner Datagroup
                                var sumBinding = new Binding();
                                sumBinding.Source = dataPointGroup;
                                sumBinding.Mode = BindingMode.OneWay;
                                sumBinding.Path = new PropertyPath("SumOfDataPointGroup");
                                BindingOperations.SetBinding(datapoint, DataPoint.SumOfDataPointGroupProperty, sumBinding);

                                var selectionBinding = new Binding();
                                selectionBinding.Source = dataPointGroup;
                                selectionBinding.Mode = BindingMode.TwoWay;
                                selectionBinding.Path = new PropertyPath("SelectedItem");
                                BindingOperations.SetBinding(datapoint, DataPoint.SelectedItemProperty, selectionBinding);

                                dataPointGroup.DataPoints.Add(datapoint);
                                seriesIndex++;
                            }
                        }
                    }
                }

                ///gehe alle Series durch (Security, Naming etc.)
                foreach (ChartSeries series in this.Series)
                {
                    foreach (var seriesItem in series.Items)
                    {
                        string seriesItemCaption = GetPropertyValue(seriesItem, series.DisplayMember); //Security

                        //finde die gruppe mit dem Namen
                        DataPointGroup addToGroup = result.Where(group => group.Caption == seriesItemCaption).FirstOrDefault();

                        //finde in der Gruppe 
                        DataPoint groupdItem = addToGroup.DataPoints.Where(item => item.SeriesCaption == series.Caption).FirstOrDefault();
                        groupdItem.ReferencedObject = seriesItem;                        
                    }
                }
                //UpdateMaxValue(maxValue);                        
            }
            catch (Exception ex)
            {
            }

            //finished, copy all to the array
            groupedSeries.Clear();
            foreach (var item in result)
            {
                groupedSeries.Add(item);
            }
            RecalcSumOfDataPointGroup();
        }
コード例 #2
0
ファイル: ChartBase.cs プロジェクト: yangdaichun/ZHXY.ZSXT
        private void UpdateGroupedPieSeries()
        {
            //gruppiere die Series neu
            List<DataPointGroup> result = new List<DataPointGroup>();
            try
            {
                ///sammle erst alle Gruppen zusammen
                foreach (ChartSeries initialSeries in this.Series)
                {
                    if (initialSeries.Items != null)
                    {
                        if (initialSeries.Items.Count > 0)
                        {
                            DataPointGroup addToGroup = new DataPointGroup();
                            addToGroup.Caption = initialSeries.Caption;
                            //addToGroup.PropertyChanged += addToGroup_PropertyChanged;
                            result.Add(addToGroup);

                            var groupBinding = new Binding();
                            groupBinding.Source = this;
                            groupBinding.Mode = BindingMode.TwoWay;
                            groupBinding.Path = new PropertyPath("SelectedItem");
                            BindingOperations.SetBinding(addToGroup, DataPointGroup.SelectedItemProperty, groupBinding);

                            int seriesIndex = 0;
                            foreach (var seriesItem in initialSeries.Items)
                            {
                                DataPoint groupdItem = new DataPoint();
                                addToGroup.DataPoints.Add(groupdItem);

                                groupdItem.SeriesCaption = initialSeries.Caption;
                                groupdItem.ValueMember = initialSeries.ValueMember;
                                groupdItem.DisplayMember = initialSeries.DisplayMember;
                                groupdItem.ItemBrush = GetItemBrush(seriesIndex);
                                groupdItem.ReferencedObject = seriesItem;

                                var selectionBinding = new Binding();
                                selectionBinding.Source = addToGroup;
                                selectionBinding.Mode = BindingMode.OneWay;
                                selectionBinding.Path = new PropertyPath("SelectedItem");
                                BindingOperations.SetBinding(groupdItem, DataPoint.SelectedItemProperty, selectionBinding);

                                var sumBinding = new Binding();
                                sumBinding.Source = addToGroup;
                                sumBinding.Mode = BindingMode.OneWay;
                                sumBinding.Path = new PropertyPath("SumOfDataPointGroup");
                                BindingOperations.SetBinding(groupdItem, DataPoint.SumOfDataPointGroupProperty, sumBinding);

                                
                                seriesIndex++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            //is there a whole change or only a change at the end??
            groupedPieSeries.Clear();            
            foreach (var item in result)
            {
                groupedPieSeries.Add(item);
            }
        }