The legend does not react when the visibility of one of the series changes

3 posts, 0 answers
  1. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 23 May 2018 Link to this post

    I create a radChartView with three bar series and a legend and show it on the form.
    Then I change runtime programatically the appearance of the two series (I make them invisible: IsVisible = false), but the legend remains the same.

    For comparison - in the MSChart such stupidity is not observed

  2. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 23 May 2018 in reply to Valery Link to this post

    Pictures
  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3466 posts

    Posted 24 May 2018 Link to this post

    Hello, Valery,    

    By design, RadChartView doesn't hide the legend items if the associated series is hidden. However, it can be easily achieved. Here is demonstrated a sample code snippet:

    public RadForm1()
    {
        InitializeComponent();
     
        LineSeries barSeries = new LineSeries();
        barSeries.LegendTitle = "Q1";
        barSeries.DataPoints.Add(new CategoricalDataPoint(177, "Harley"));
        barSeries.DataPoints.Add(new CategoricalDataPoint(128, "White"));
        barSeries.DataPoints.Add(new CategoricalDataPoint(143, "Smith"));
        barSeries.DataPoints.Add(new CategoricalDataPoint(111, "Jones"));
        barSeries.DataPoints.Add(new CategoricalDataPoint(118, "Marshall"));
        this.radChartView1.Series.Add(barSeries);
        LineSeries barSeries2 = new LineSeries();
        barSeries2.LegendTitle = "Q2";
        barSeries2.DataPoints.Add(new CategoricalDataPoint(153, "Harley"));
        barSeries2.DataPoints.Add(new CategoricalDataPoint(141, "White"));
        barSeries2.DataPoints.Add(new CategoricalDataPoint(130, "Smith"));
        barSeries2.DataPoints.Add(new CategoricalDataPoint(88, "Jones"));
        barSeries2.DataPoints.Add(new CategoricalDataPoint(109, "Marshall"));
        this.radChartView1.Series.Add(barSeries2);
     
        this.radChartView1.ShowLegend = true;
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radChartView1.Series[0].IsVisible = !this.radChartView1.Series[0].IsVisible;
     
        foreach (LegendItemElement itemElement in this.radChartView1.ChartElement.LegendElement.StackElement.Children)
        {
            LineSeries s = itemElement.LegendItem.Element as LineSeries;
            if (s != null)
            {
                if (s.IsVisible)
                {
                    itemElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                }
                else
                {
                    itemElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                }
            }
        }
    }

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top