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.
Unfortunately, activation email could not send to your email. Please try again.

Multiple windows chart series

Thread ID:

Created:

Updated:

Platform:

Replies:

71664 Feb 8,2008 01:13 PM Feb 12,2008 02:46 PM WPF 4
loading
Tags: Chart
Bestin Abraham
Asked On February 8, 2008 01:13 PM

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.



Administrator [Syncfusion]
Replied On February 11, 2008 05:57 AM

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


Bestin Abraham
Replied On February 11, 2008 09:12 AM

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

Administrator [Syncfusion]
Replied On February 12, 2008 05:04 AM

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.


Bestin Abraham
Replied On February 12, 2008 02:46 PM

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.




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;