OnMouseDown event on TIWChart does not work

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Stephen
Newbie
Newbie
Posts: 5
Joined: Thu Feb 16, 2012 12:00 am

OnMouseDown event on TIWChart does not work

Post by Stephen » Tue Jul 10, 2012 5:44 am

Hi,

I'm currently trying to use TeeChart in an Intraweb application. I am using Delphi XE, TeeChart 2012 and Intraweb XII.

My problem is that the OnMouseDown event of the TIWChart does not seem to occur when I click on the generated chart in my web browser. This is rather strange, since if I change the event to an OnClick event, then this DOES occur when I click on the chart in the web browser.

For reference, I have done the following:
- downloaded "TeeChart 2010 Standard for IntraWeb XI and Delphi XE" from http://www.steema.com/download/vcl
- changed "Tee" to "Tee915" and "IWExtCtrls" to "IWCompExtCtrls"
- built the packages and installed the TIWChart component
- created a new Intraweb application
- added a TChart and a TIWChart component to the design page, as well as a TIWLabel
- set the Chart property of the TIWChart to the name of the TChart
- added an OnMouseDown event to the TIWChart

Can you advise me what I need to do to get the OnMouseDown event of the TIWChart working? Alternatively, how can I find out where a user has clicked on the TIWChart?


Many thanks,

Stephen

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnMouseDown event on TIWChart does not work

Post by Yeray » Wed Jul 11, 2012 2:10 pm

Hi Stephen,

We'll prepare an environment like yours and investigate it as soon as possible.
In the meanwhile, isn't the OnClick event offer an acceptable workaround for you?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Stephen
Newbie
Newbie
Posts: 5
Joined: Thu Feb 16, 2012 12:00 am

Re: OnMouseDown event on TIWChart does not work

Post by Stephen » Thu Jul 12, 2012 5:09 am

Hi Yeray,

The problem I have with the OnClick event is that it does not give me the position of the cursor when it is clicked.

I am trying to identify where the user has clicked in the plot. How should I do this via the OnClick event?


Many thanks,

Stephen

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnMouseDown event on TIWChart does not work

Post by Yeray » Thu Jul 12, 2012 8:14 am

Hi Stephen,
Stephen wrote:The problem I have with the OnClick event is that it does not give me the position of the cursor when it is clicked.

I am trying to identify where the user has clicked in the plot. How should I do this via the OnClick event?
Ah, I understood the event wasn't fired at all!
Right, the OnClick event doesn't give you the mouse position. However, this event is fired later than the OnMouseDown/OnMouseMove events, events that give you the mouse coordinates. So you could save the current mouse position in global variables with one of these events and use that variable at OnClick event.
Don't hesitate to let us know if you still find problems with it.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Stephen
Newbie
Newbie
Posts: 5
Joined: Thu Feb 16, 2012 12:00 am

Re: OnMouseDown event on TIWChart does not work

Post by Stephen » Fri Jul 13, 2012 12:56 am

Yeray,

You are correct in understanding that the OnMouseDown event DOES NOT fire at all. That means that I still have the same problem of not being able to recover the mouse coordinates on click or mouse down.


Stephen

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnMouseDown event on TIWChart does not work

Post by Yeray » Wed Jul 18, 2012 10:23 am

Hi Stephen,

You are right. However, I've observed you can get the mouse position with:

Code: Select all

Mouse.CursorPos.X
Mouse.CursorPos.Y
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Stephen
Newbie
Newbie
Posts: 5
Joined: Thu Feb 16, 2012 12:00 am

Re: OnMouseDown event on TIWChart does not work

Post by Stephen » Fri Jul 20, 2012 3:45 am

Hi Yeray,

Thank you for your response.

Mouse.CursorPos.X and Mouse.CursorPos.Y give me absolute screen coordinates.

To convert these absolute screen coordinates into local coordinates relative to the TChart axes, I need to know where the TChart axes are plotted. I can see that TChart.ChartRect will give me the coordinates within the TIWChart region, and TIWChart.BoundsRect will give me the coordinates within the browser window. I see no obvious way to get the position of the browser window relative to screen coordinates without installing the components from http://code.google.com/p/iwopensource/.

Am I missing something? Is there some easier way to get the local coordinates relative to the TChart axes?


Stephen

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnMouseDown event on TIWChart does not work

Post by Yeray » Fri Jul 20, 2012 4:04 pm

Hi Stephen,

I'm afraid TeeChart doesn't know the browser position to calculate the chart position relative to it, and substract that from the absolute mouse coordinates.
Maybe Atozed guys know a way to get the mouse coordinates relative to the browser or how to calculate them.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Stephen
Newbie
Newbie
Posts: 5
Joined: Thu Feb 16, 2012 12:00 am

Re: OnMouseDown event on TIWChart does not work

Post by Stephen » Wed Jul 25, 2012 4:53 am

OK, I've found a workaround. Now, I work directly with the TIWImage component.

After adding the TIWImage component (called imgIWChart) and a TChart component (called chtOriginal), I use the following function to render the TChart in the TIWImage:

procedure TIWForm1.RedrawGraph;
var
lMF : TMetafile;
lBitmap : TBitmap;
lRect : TRect;
begin
// set the image dimensions of imgIWChart
lBitmap := imgIWChart.Picture.Bitmap;
lBitmap.Width := chtOriginal.Width;
lBitmap.Height := chtOriginal.Height;
imgIWChart.Width := chtOriginal.Width;
imgIWChart.Height := chtOriginal.Height;

// set the drawing rectangle for the TChart
lRect.Left := 0;
lRect.Top := 0;
lRect.Right := chtOriginal.Width;
lRect.Bottom := chtOriginal.Height;
try
// create an image metafile from the TChart
lMF := chtOriginal.TeeCreateMetafile(False, lRect);

// draw the metafile into the bitmap
lBitmap.Canvas.Draw(0, 0, lMF);
finally
FreeAndNil(lMF);
end;
end;

Then, I use the OnAsyncMouseDown event for the TIWImage to give me the local coordinates within the TIWImage component, and map these into local TChart coordinates via TChart.ChartRect.


Stephen

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: OnMouseDown event on TIWChart does not work

Post by Yeray » Thu Jul 26, 2012 3:19 pm

Hi Stephen,

Great! Thanks for sharing! :D
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply