This is a migrated thread and some comments may be shown as answers.
The legend does not react when the visibility of one of the series changes
2 Answers 7 Views
This is a migrated thread and some comments may be shown as answers.
Valery
Top achievements
Rank 1
Valery asked on 23 May 2018, 12:26 PM

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 Answers, 1 is accepted

Sort by
0
Valery
Top achievements
Rank 1
answered on 23 May 2018, 12:28 PM
0
Dess | Tech Support Engineer, Sr.
Telerik team
answered on 24 May 2018, 10:52 AM
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.
Asked by
Valery
Top achievements
Rank 1
Answers by
Valery
Top achievements
Rank 1
Dess | Tech Support Engineer, Sr.
Telerik team
Share this question
or