EDIT: I solved the issue, I just had to create a new background worker for each series.
Hey peeps,
I'm just getting started with Telerik's controls and have successfully managed to plot a multi series chart. Now due to the time it takes to populate the chartdata, I wanted to do this with a background worker. I successfully managed to have a backgroundworker plot a single chartseries, but I don't know how to have it plot multiple. Lets look at the code:
The code above populates chartData1 and chartData2, but only allows me to return a single type(chartdataclass1 OR chartdataclass2). My question is, what must I do so that I can return chartData1 AND chartData2 to e.Result? Also, assuming I can return both, how do I then set up e.Result such that I can define Series[0] and Series[1] using e.Result?
Hey peeps,
I'm just getting started with Telerik's controls and have successfully managed to plot a multi series chart. Now due to the time it takes to populate the chartdata, I wanted to do this with a background worker. I successfully managed to have a backgroundworker plot a single chartseries, but I don't know how to have it plot multiple. Lets look at the code:
public BackgroundWorker worker = new BackgroundWorker(); public Window1() { InitializeComponent(); InitializeBackgroundWorker(); } // Set up the BackgroundWorker object by // attaching event handlers. private void InitializeBackgroundWorker() { worker.DoWork +=new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted +=new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); } //Define a New Chart Data Class for each graph public class ChartDataClass1 { public double X1 { get; set; } public double Y1 { get; set; } public ChartDataClass1() { } } public class ChartDataClass2 { public double X2 { get; set; } public double Y2 { get; set; } public ChartDataClass2() { } } private void btn1_Click(object sender, RoutedEventArgs e) { worker.RunWorkerAsync(); } void worker_DoWork(object sender, DoWorkEventArgs e) { // On the worker thread...cannot make UI calls from here. e.Result = MTLB(worker,e); } private void worker_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e) { // First, handle the case where an exception was thrown. if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { // Finally, handle the case where the operation // succeeded. xline.Series[0].ItemsSource = (System.Collections.IEnumerable)e.Result; } } public System.Collections.Generic.List<ChartDataClass1> MTLB(BackgroundWorker worker, DoWorkEventArgs e) { int st = 1; int sp = 20; //MATLAB inputs MWNumericArray start = 1; MWNumericArray stop = 20; //MATLAB fn Reactor.Class1 rxtr_lib = new Reactor.Class1(); MWArray[] result = rxtr_lib.rxtr(1, start, stop); System.Array NH3 = new double[2 * (sp - st + 1)]; NH3 = ((MWNumericArray)result[0]).ToVector(MWArrayComponent.Real); List<ChartDataClass1> chartData1 = new List<ChartDataClass1>(); List<ChartDataClass2> chartData2 = new List<ChartDataClass2>(); for (int i = 0; i < (sp - st); i++) { ChartDataClass1 cdc = new ChartDataClass1(); ChartDataClass2 cdc2 = new ChartDataClass2(); cdc.X1 = i; cdc.Y1 = Convert.ToDouble(NH3.GetValue(2 * i)); cdc2.X2 = i; cdc2.Y2 = Convert.ToDouble(NH3.GetValue(2 * i + 1)); chartData1.Add(cdc); chartData2.Add(cdc2); } return chartData1; }The code above populates chartData1 and chartData2, but only allows me to return a single type(chartdataclass1 OR chartdataclass2). My question is, what must I do so that I can return chartData1 AND chartData2 to e.Result? Also, assuming I can return both, how do I then set up e.Result such that I can define Series[0] and Series[1] using e.Result?
