Exemple #1
0
        private LegendItem GetWaterfallLegendItem(object source, string label, int index, ChartLegend legend)
        {
            var legenditem = new LegendItem
            {
                Index  = index,
                Series = VisibleSeries[0],
                Legend = legend
            };

            Binding binding = new Binding();

            binding.Source = source;
            binding.Path   = new PropertyPath("Interior");
            BindingOperations.SetBinding(legenditem, LegendItem.InteriorProperty, binding);
            legenditem.Label = label;

            return(legenditem);
        }
Exemple #2
0
        internal void ComputeToggledSegment(ChartSeriesBase series, LegendItem legendItem)
        {
            var toggledSegment = GetSegment(series.Segments, legendItem.Item);
            var circularSeries = series as CircularSeriesBase;
            int toggledIndex   = circularSeries != null && !double.IsNaN(circularSeries.GroupTo) ? series.Segments.IndexOf(toggledSegment) : series.ActualData.IndexOf(legendItem.Item);

            if (toggledSegment != null && toggledSegment.IsSegmentVisible)
            {
                series.ToggledLegendIndex.Add(toggledIndex);
                toggledSegment.IsSegmentVisible = false;
                legendItem.Opacity = 0.5d;
            }
            else
            {
                series.ToggledLegendIndex.Remove(toggledIndex);
                toggledSegment.IsSegmentVisible = true;
                legendItem.Opacity = 1d;
            }
            ChartArea.ScheduleUpdate();
        }
Exemple #3
0
        private static void OnSeriesVisible(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            LegendItem legendItem = d as LegendItem;

            legendItem.OnPropertyChanged("IsSeriesVisible");
            var series = legendItem.legend.ChartArea.ActualSeries;

            if (series[0].IsSingleAccumulationSeries && !legendItem.legend.isSegmentsUpdated)
            {
                legendItem.legend.ComputeToggledSegment(series[0], legendItem);
            }
            else
            {
                if (legendItem.IsSeriesVisible)
                {
                    legendItem.Opacity = 1d;
                }
                else
                {
                    legendItem.Opacity = 0.5d;
                }
            }
        }
Exemple #4
0
        private void SetLegendItems(ChartLegend legend, int index)
        {
            var  series         = HasDataPointBasedLegend() ? legend.Series : VisibleSeries[0];
            var  yvalues        = series.ActualSeriesYValues[0] as List <double>;//When EmptyPoint is set last legend is not rendered.-WPF-18794
            var  circularSeries = series as CircularSeriesBase;
            bool isGroupTo      = circularSeries != null && !double.IsNaN(circularSeries.GroupTo);

            if (isGroupTo)
            {
                var groupToYValues = circularSeries.GetGroupToYValues();
                yvalues = groupToYValues.Item1 as List <double>;
            }

            LegendItems[index].Clear();
            int j        = 0;
            var Segments = series.Segments.ToList();

            if (series is FunnelSeries)
            {
                Segments.Reverse();
            }
            for (int i = 0; i < yvalues.Count; i++)
            {
                var legendIndex = i;
                if (double.IsNaN(yvalues[i]))
                {
                    if (!(series is TriangularSeriesBase) && !(series is CircularSeriesBase3D))
                    {
                        j++;
                    }
                    continue;
                }
                LegendItem legenditem;

                //Created duplicate legends to measure if segments are not created WPF-26728
                if (Segments.Count == 0)
                {
                    legenditem = new LegendItem
                    {
                        Index  = legendIndex,
                        Series = series,
                        Legend = legend
                    };
                }
                else
                {
                    var item = Segments[j];
                    legenditem = new LegendItem
                    {
                        Index  = legendIndex, //WPF-14337 Legend value wrong while using empty point in accumulation series
                        Item   = item.Item,
                        Series = series,
                        Legend = legend
                    };

                    if (series.ToggledLegendIndex.Count > 0 && (legend.CheckBoxVisibility == Visibility.Visible || legend.ToggleSeriesVisibility))
                    {
                        if (!item.IsSegmentVisible)
                        {
                            legend.isSegmentsUpdated   = true;
                            legenditem.IsSeriesVisible = false;
                            legend.isSegmentsUpdated   = false;
                        }
                    }

                    Binding binding = new Binding();
                    binding.Source = item;
                    binding.Path   = new PropertyPath("Interior");
                    BindingOperations.SetBinding(legenditem, LegendItem.InteriorProperty, binding);
                }

                if (isGroupTo && circularSeries.GroupedData.Count > 0 && legenditem.Index == Segments.Count - 1)
                {
                    legenditem.Label = circularSeries.GroupingLabel;
                }
                else if (legenditem.Item != null)
                {
                    legenditem.Label = series.GetActualXValue(series.ActualData.IndexOf(legenditem.Item)).ToString();
                }
                else
                {
                    legenditem.Label = series.GetActualXValue(legenditem.Index).ToString();
                }
                LegendItems[index].Add(legenditem);

                j++;
            }
        }
Exemple #5
0
        internal void SetLegendItemsSource(ChartLegend legend, int index)
        {
            if (legend == null || ActualSeries == null)
            {
                return;
            }
            legend.ChartArea = this;
            //HasDataPointBasedLegend() will return true when need to generate data point based legend items.
            if ((VisibleSeries.Count == 1 && VisibleSeries[0].IsSingleAccumulationSeries) || HasDataPointBasedLegend())
            {
                SetLegendItems(legend, index);
            }
            else if (VisibleSeries.Count == 1 && VisibleSeries[0] is WaterfallSeries)
            {
                SetWaterfallLegendItems(legend, index);
                legend.XAxis = VisibleSeries[0].IsActualTransposed ? (VisibleSeries[0] as ISupportAxes).ActualYAxis : (VisibleSeries[0] as ISupportAxes).ActualXAxis;
                legend.YAxis = VisibleSeries[0].IsActualTransposed ? (VisibleSeries[0] as ISupportAxes).ActualXAxis : (VisibleSeries[0] as ISupportAxes).ActualYAxis;
            }
            else
            {
                var technicalIndicators = new List <ChartSeriesBase>();
                var sfChart             = this as SfChart;
                if (sfChart != null)
                {
                    foreach (ChartSeries indicator in sfChart.TechnicalIndicators)
                    {
                        technicalIndicators.Add(indicator as ChartSeriesBase);
                    }
                }

                List <ChartSeriesBase> actualLegendSeries = sfChart != null?ActualSeries.Union(technicalIndicators).ToList() : ActualSeries;

                if (AreaType == ChartAreaType.PolarAxes || AreaType == ChartAreaType.CartesianAxes && Legend is ChartLegendCollection)
                {
                    actualLegendSeries = (from actualSeries in actualLegendSeries
                                          where
                                          GetActualRow(legend) == GetActualRow(actualSeries.IsActualTransposed ? actualSeries.ActualXAxis : actualSeries.ActualYAxis) &&
                                          GetActualColumn(legend) == GetActualColumn(actualSeries.IsActualTransposed ? actualSeries.ActualYAxis : actualSeries.ActualXAxis)
                                          select actualSeries).ToList();
                }

                if (actualLegendSeries.Count > 0 && actualLegendSeries[0] is ISupportAxes)
                {
                    legend.XAxis = actualLegendSeries[0].IsActualTransposed ? (actualLegendSeries[0] as ISupportAxes).ActualYAxis : (actualLegendSeries[0] as ISupportAxes).ActualXAxis;
                    legend.YAxis = actualLegendSeries[0].IsActualTransposed ? (actualLegendSeries[0] as ISupportAxes).ActualXAxis : (actualLegendSeries[0] as ISupportAxes).ActualYAxis;
                }

                IEnumerable <ChartSeriesBase> legendSeries;
                switch (AreaType)
                {
                case ChartAreaType.CartesianAxes:

                    legendSeries = from series in actualLegendSeries
                                   where series is ISupportAxes2D || series is ISupportAxes3D
                                   select series;
                    break;

                case ChartAreaType.PolarAxes:
                    legendSeries = from series in actualLegendSeries
                                   where series is PolarRadarSeriesBase
                                   select series;
                    break;

                default:
                    legendSeries = from series in actualLegendSeries
                                   where series is AccumulationSeriesBase || series is CircularSeriesBase3D
                                   select series;
                    break;
                }
                var chartSeries = legendSeries as ChartSeries[] ?? legendSeries.ToArray();

                foreach (var series in chartSeries)
                {
                    if (series.IsSeriesVisible)
                    {
                        if (LegendItems[index].Count > 0 && index < LegendItems[index].Count)//Legend not cleared when bind Series in MVVM view model-WPF-18625
                        {
                            LegendItems[index].Clear();
                        }
                    }
                }
                foreach (var item in chartSeries.Where(series => series.VisibilityOnLegend == Visibility.Visible))
                {
                    var containlegenditem = LegendItems[index].Where(it => it.Series == item).ToList();
                    if (LegendItems.Count == 0 || containlegenditem.Count() == 0)
                    {
                        var legenditem = new LegendItem {
                            Legend = legend, Series = item
                        };
                        if (item.IsSingleAccumulationSeries)
                        {
                            legenditem.Legend.isSegmentsUpdated = true;
                            if (item.IsSeriesVisible)
                            {
                                legenditem.IsSeriesVisible = true;
                            }
                            else
                            {
                                legenditem.IsSeriesVisible = false;
                            }
                            legenditem.Legend.isSegmentsUpdated = false;
                        }
                        LegendItems[index].Add(legenditem);
                    }
                }
                foreach (var item in chartSeries)
                {
                    var cartesian = item as CartesianSeries;
                    if (cartesian != null)
                    {
                        foreach (var trend in cartesian.Trendlines.Where(
                                     trendline => trendline.VisibilityOnLegend == Visibility.Visible))
                        {
                            var containlegenditem = LegendItems[index].Where(it => it.Trendline == trend).ToList();
                            if (LegendItems.Count == 0 || containlegenditem.Count() == 0)
                            {
                                var trendline = new LegendItem {
                                    Legend = legend, Trendline = trend
                                };
                                LegendItems[index].Add(trendline);
                                trend.UpdateLegendIconTemplate(true);
                            }
                        }
                    }
                }
            }
        }