I have a RadChart that has a dynamic set of lineSeries that i add to it after recieving the data from an end device. When i try to clear the Chart for new data, the legend Items do not get cleared.
After the initial load, the legend items just append to the legend. So i get repeat Series legend items. Its not being cleared on the Legend.Items.Clear() method.
private
void
AddTrendPoints(TrendFiles trendfile)
{
if
(
this
.trendGraph.Dispatcher.Thread != Thread.CurrentThread)
{
this
.trendGraph.Dispatcher.Invoke(DispatcherPriority.Normal,
new
DispatcherOperationCallback(
delegate
{
#region Setup Series
this
.trendGraph.DefaultView.ChartArea.DataSeries.Clear();
this
.trendGraph.DefaultView.ChartArea.Legend.Items.Clear();
this
.trendGraph.SamplingSettings.SamplingThreshold = trendfile.Records;
DataSeries series =
new
DataSeries();
LineSeriesDefinition lineDefinition =
new
LineSeriesDefinition();
ChartLegendItem legendItem =
new
ChartLegendItem();
int
count = 0;
foreach
(TrendVariable trendVar
in
trendfile.Variables)
{
series =
new
DataSeries();
lineDefinition =
new
LineSeriesDefinition();
legendItem =
new
ChartLegendItem();
lineDefinition.ShowItemLabels =
false
;
lineDefinition.ShowPointMarks =
false
;
lineDefinition.SeriesName = trendVar.Name;
lineDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
series.LegendLabel = trendVar.Name;
series.Definition = lineDefinition;
series.Definition.Appearance.Stroke = colors[count];
series.Definition.Appearance.Fill = colors[count];
legendItem.Label = trendVar.Name;
legendItem.Background = colors[count];
legendItem.Foreground = Brushes.White;
trendGraph.DefaultView.ChartLegend.Items.Add(legendItem);
foreach
(DataPoint point
in
trendVar.points)
{
series.Add(point);
}
trendGraph.DefaultView.ChartArea.DataSeries.Add(series);
count++;
}
#endregion
return
null
;
}),
null
);
}
else
{
#region Setup Series
this
.trendGraph.DefaultView.ChartArea.DataSeries.Clear();
this
.trendGraph.DefaultView.ChartArea.Legend.Items.Clear();
DataSeries series =
new
DataSeries();
LineSeriesDefinition lineDefinition =
new
LineSeriesDefinition();
ChartLegendItem legendItem =
new
ChartLegendItem();
int
count = 0;
foreach
(TrendVariable trendVar
in
trendfile.Variables)
{
series =
new
DataSeries();
lineDefinition =
new
LineSeriesDefinition();
legendItem =
new
ChartLegendItem();
lineDefinition.ShowItemLabels =
false
;
lineDefinition.ShowPointMarks =
false
;
lineDefinition.SeriesName = trendVar.Name;
lineDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
series.LegendLabel = trendVar.Name;
series.Definition = lineDefinition;
series.Definition.Appearance.Stroke = colors[count];
series.Definition.Appearance.Fill = colors[count];
legendItem.Label = trendVar.Name;
legendItem.Background = colors[count];
legendItem.Foreground = Brushes.White;
trendGraph.DefaultView.ChartLegend.Items.Add(legendItem);
foreach
(DataPoint point
in
trendVar.points)
{
series.Add(point);
}
trendGraph.DefaultView.ChartArea.DataSeries.Add(series);
count++;
}
#endregion
}
}
After the initial load, the legend items just append to the legend. So i get repeat Series legend items. Its not being cleared on the Legend.Items.Clear() method.