|
Prevent simultaneous hotspot click events in pie chart |
Posted by Revathi on Jan-12-2015 20:06 |
|
Hello,
I am developing a C# application where I use clickable pie charts.
I have written the hotspot click event to obtain the title of the clicked sector as follows:
private void folderChartViewer_ClickHotSpot(object sender, WinHotSpotEventArgs e)
{
Hashtable t = e.AttrValues;
string original = t["title"].ToString();
System.Diagnostics.Debug.WriteLine(original);
string[] temp = original.Split('(');
string folder = temp[0].Substring(0, temp[0].Length - 1);
System.Diagnostics.Debug.WriteLine(folder);
}
The issue I am facing is that when two sectors of the pie chart are clicked one after the
other with very little delay, the title of both sectors appears in e.Attrvalues["title"] and
hence the string folder has the title of both sectors.
Eg. If sector 1 with title Windows (56.67 %) and sector 2 with title Users (23.64 %) are
clicked simultaneously, the variable folder has the value WindowsUsers instead of just
Windows.
How do I disable/ prevent hot spot click event of the chart until the functions in the
previous click event is complete? I tried WinchartViewer.Enabled = false but it does not
solve the problem.
Kindly help me out ASAP.
Regards,
Revathi |
Re: Prevent simultaneous hotspot click events in pie chart |
Posted by Peter Kwan on Jan-13-2015 04:28 |
|
Hi Revathi,
I have tried myself and cannot reproduce this problem. Also, the design of ChartDirector
is such that the event arguments should not be able to mix up. Internal to ChartDirector,
each hotspot contains a separate Hashtable containing the attributes of the hot spot,
and the Hashtable never changed, and the WinHotSpotEventArgs are just referencing
that Hashtable.
In a Hashtable, each key can only exists once, so there can only be one "title". Even if
the value of two hot spots are mixed up in one title, it should be something like "Windows
(56.67 %)Users (23.64 %)", and not "WindowsUsers(xxx%)".
To test more clearly, is it possible to use the following code:
private void folderChartViewer_ClickHotSpot(object sender, WinHotSpotEventArgs e)
{
System.Diagnostics.Debug.WriteLine("[" + e.AttrValues["title"] + "]");
}
In your original code, I am thinking may be the Debug.WriteLine can mix up the text. In
the above code, I use square brackets "[.....]" to enclose the title so that you can see
where is the border of the title.
If your actual code has more lines, please make sure your code do not modify the
e.AttrValues (by assigning values to it). It should be read only.
If your code is multi-threaded, please make sure the GUI part is running in the GUI thread
and not on multiple threads. Variables used in the GUI thread (such as the event
arguments above) should remain in the GUI thread and not in other thread.
Regards
Peter Kwan |
|