We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Multiple windows chart series

I have a window1.xaml and creating chart dynamically. Also i am opening multiple "window1" windows using backgroudworker. Only first window create the chart and Next window thrown an exception because checkaccess failed. I can create all other UIElement with out any problem. But cannot create chart.


Window1 tempwindow=new Window1();
tempwindow.show()
System.Windows.Threading.Dispatcher.Run();

On window1 i have backgroudworker thread and call dispacher.begininvoke to create chart.



4 Replies

AD Administrator Syncfusion Team February 11, 2008 10:57 AM UTC

Hi Bestin Abraham,

I have analyzed your issue and I found that like all other UIElement, you can also create Syncfusion WPF chart by using BackgroundWorker thread and call Dispatcher.BeginInvoke() function to draw the chart. You can also open multiple windows using BackgroundWorker. The following lines of code can be used to WPF chart in multiple windows using BackgroundWorker thread.


namespace MultipleWindowChart
{
public partial class Window1 : Window
{
private BackgroundWorker backgroundWorker1;
public delegate void SomeDelegate();

public Window1()
{
InitializeComponent();
this.backgroundWorker1 = new BackgroundWorker();
createChart();
}
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new SomeDelegate(newWindow));
}
private void createChart()
{
Chart chart = new Chart();
chart.Background = Brushes.Yellow;
chart.Areas.Add(new ChartArea());
chart.Areas[0].Series.Add(new ChartSeries(ChartTypes.Line));
ChartListData listData = new ChartListData();
listData.Add(new ChartPoint(1,20));
listData.Add(new ChartPoint(2, 27));
listData.Add(new ChartPoint(3, 7));
listData.Add(new ChartPoint(4, 15));
listData.Add(new ChartPoint(5, 3));
listData.Add(new ChartPoint(6, 25));
listData.Add(new ChartPoint(7, 20));
listData.Add(new ChartPoint(8, 10));
chart.Areas[0].Series[0].Data = listData;
Grid1.Children.Add(chart);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerAsync();
}
public void newWindow()
{
Window1 tempWindow = new Window1();
tempWindow.Show();
System.Windows.Threading.Dispatcher.Run();
createChart();
}
}
}


I hope these codes will help you overcome the issue. If you still find problems then kindly add some more code snippets so that I can help you better.

Please let me know if you have any question.

Thanks for interest in Syncfusion products.

Regard,
Asem



BA Bestin Abraham February 11, 2008 02:12 PM UTC

Thank you for your Response. I have attached a solution file.
I have window1 from your code and window2 from your code. I have used a new thread to create window1. If i am using dispacher everything will work fine. But on my window creation is long process and i don't want to wait for that. As you see on window1 i commented createchart() function everything will work fine. I have attached the button click on the window1 to call createchart. And work fine first time. Not any other windows. I can create chart with in that window number of times.

>I have a window1.xaml and creating chart dynamically. Also i am opening multiple "window1" windows using backgroudworker. Only first window create the chart and Next window thrown an exception because checkaccess failed. I can create all other UIElement with out any problem. But cannot create chart.


Window1 tempwindow=new Window1();
tempwindow.show()
System.Windows.Threading.Dispatcher.Run();

On window1 i have backgroudworker thread and call dispacher.begininvoke to create chart.






SyncChart.zip


AD Administrator Syncfusion Team February 12, 2008 10:04 AM UTC

Hi Bestin,

You cannot create the ChartArea object across the thread boundaries. If you need access to the UI objects or other DependencyObjects created on the UI thread, use the Dispatcher (Dispatcher.Invoke) to get access to the UI thread safely. In your case, I would like to suggest using Dispatcher.Invoke to get access to the thread. The same issue occurs even when you use FlowDocument on another thread.

Please let me know if you have any question.

Thanks for interest in Syncfusion products.

Regards,
Asem.



BA Bestin Abraham February 12, 2008 07:46 PM UTC

Sorry to tell you that I found another tool infragistics's chart, which doesn't have any problem and working fine.



>Hi Bestin,

You cannot create the ChartArea object across the thread boundaries. If you need access to the UI objects or other DependencyObjects created on the UI thread, use the Dispatcher (Dispatcher.Invoke) to get access to the UI thread safely. In your case, I would like to suggest using Dispatcher.Invoke to get access to the thread. The same issue occurs even when you use FlowDocument on another thread.

Please let me know if you have any question.

Thanks for interest in Syncfusion products.

Regards,
Asem.




Loader.
Live Chat Icon For mobile
Up arrow icon