I've got 3 charts in my app. When I don't specify a series.Definition, it works great. When I do, I find that it locks up my app if I call DataSeries.Clear() or if I try to replace a data series. I found a kludgey work-around by calling DataSeries.Reset(), then re-adding the data series, however, I'm seeing a lot of overhead with this method.
When I tried to create my DataSeries on a background thread, then call Dispatcher.BeginInvoke() to update the graph on the UI, I'm getting, "The calling thread cannot access this object because a different thread owns it." If I remove the series.Defintion and have the graph draw as a bar graph instead of a line graph, there are no problems whatsoever.
I'm supposed to be showing this at a trade show tomorrow and I'm stuck. It appears that when I specify a LineSeriesDefinition, a new thread internal to the control is introduced into the equation and it's wreaking havoc. Help!
Below is some of the code.
StartUpdatingCharts() is called from a timer:
protected void StartUpdatingCharts(object dummy)
foreach (object currentGraph in ActiveGraphs)
Thread t = new Thread(UpdateChartInBackground);
public void UpdateChartInBackground(Object threadContext)
GraphControl currentGraph = threadContext as GraphControl;
FillChartWithData() is called from a background thread:
protected override void FillChartWithData(GraphControl graphControl)
Dictionary<string, double> returnValues = Msi.GetReservoirData(graphControl.Arguments);
DataSeries series = new DataSeries();
series.Definition.ShowItemLabels = false;
LineSeriesDefinition definition = new LineSeriesDefinition();
definition.ShowItemLabels = false;
definition.ShowPointMarks = false;
//series.Definition = definition; //THIS IS THE LINE THAT CAUSES ALL OF THE PROBLEMS!
foreach (string sectionName in returnValues.Keys)
ChartArea chartArea = graphControl.RadChart.DefaultView.ChartArea;
chartArea.Dispatcher.BeginInvoke(new UpdateChart(BindDataToChart), chartArea, series);
private delegate void UpdateChart
private static void BindDataToChart(ChartArea chartArea, DataSeries series)