This is a migrated thread and some comments may be shown as answers.

RadChart Legend Will Not Show New Items

1 Answer 38 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Marie C
Top achievements
Rank 1
Marie C asked on 28 Jan 2013, 07:29 PM
I have a RadChart (2011.2.920.1040) that is filled in code behind using WCF results. The user is allowed to pick the data they want to chart.  This works the first time but if they make a second choice, the legend is empty. 

Before I cleared the dataseries, the chart and legend kept the old data along with the new.  Now that I have cleared the dataseries, if the user makes a second selection, the legend is empty. 

I manually added a legend item to the ChartLegend and the associated legend but the legend is still empty. 

// Global Variables

 

 

RadChart chartName =

new RadChart();

 

 

 

ChartLegend chartLegend =

 

 

new ChartLegend();

 

 

 

// SET LEGEND TO CHARTAREA

 

chartName.DefaultView.ChartArea.LegendName =

 

"chartLegend";

 

 

 


// Clear the previously plotted data if this is not the first time through
chartName.DefaultView.ChartArea.Legend.Items.Clear();
chartName.DefaultView.ChartArea.DataSeries.Clear();


 

// CREATE A SERIES FOR EACH SENSOR RETURNED.

 

 

foreach (var sensorItem in sensorReturned)

 

{

 

 

DataSeries lineSeries = new DataSeries();

 

lineSeries.LegendLabel = sensorItem.ToString();

lineSeries.Definition =

 

new LineSeriesDefinition();

 

 

 

var sensorPlotItems = (from p in e.Result 
                        where p.SensorName == sensorItem
                        
select p).ToList();

 

 

 

foreach (var item in sensorPlotItems)

 

{

lineSeries.Add(

 

new DataPoint() { XCategory = item.TimeStamp.ToString(), YValue = item.SelectedFieldValue, LegendLabel = sensorItem.ToString() });

 

}

chartName.DefaultView.ChartArea.DataSeries.Add(lineSeries);

 

 

ChartLegendItem legendItem = new ChartLegendItem();

 

legendItem.Label = sensorItem.ToString();

chartLegend.Items.Add(legendItem);

chartName.DefaultView.ChartLegend.Items.Add(legendItem);

 

 

// TEST TO SEE IF THE NEWLY ADDED LEGEND ITEM IS INSIDE THE LEGEND

 

 

 

bool associatedLegendFilled = chartLegend.HasItems; // true but nothing shows

 

 

 

bool filled = chartName.DefaultView.ChartLegend.HasItems; // false

 

}

Any ideas?

1 Answer, 1 is accepted

Sort by
0
Marie C
Top achievements
Rank 1
answered on 28 Jan 2013, 08:04 PM
Problem solved.  I removed the line setting the chartName.DefaultView.ChartLegend.ItemsSource = null.  All works fine now. 

 

 

// CLEAR ALL DATA FROM SELECTEDSENSORS AND CHART

 

selectedSensors.Clear();

 

 

chartName.ItemsSource =

null;

 

chartName.DefaultView.ChartArea.ItemsSource =

 

 

 

null;

 

 

 

//chartName.DefaultView.ChartLegend.ItemsSource = null;

 

chartName.DefaultView.ChartArea.AxisX.ChartArea.ItemsSource =

 

//chartName.DefaultView.ChartLegend.ItemsSource = null;

 

 

 

 

 

 

null;

 

chartName.DefaultView.ChartArea.Legend.Items.Clear();

 

 

chartName.DefaultView.ChartArea.DataSeries.Clear();

Tags
Chart
Asked by
Marie C
Top achievements
Rank 1
Answers by
Marie C
Top achievements
Rank 1
Share this question
or