Page 1 of 1

OnMouseDown event on TIWChart does not work

Posted: Tue Jul 10, 2012 5:44 am
by 16561585
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

Re: OnMouseDown event on TIWChart does not work

Posted: Wed Jul 11, 2012 2:10 pm
by yeray
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?

Re: OnMouseDown event on TIWChart does not work

Posted: Thu Jul 12, 2012 5:09 am
by 16561585
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

Re: OnMouseDown event on TIWChart does not work

Posted: Thu Jul 12, 2012 8:14 am
by yeray
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.

Re: OnMouseDown event on TIWChart does not work

Posted: Fri Jul 13, 2012 12:56 am
by 16561585
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

Re: OnMouseDown event on TIWChart does not work

Posted: Wed Jul 18, 2012 10:23 am
by yeray
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

Re: OnMouseDown event on TIWChart does not work

Posted: Fri Jul 20, 2012 3:45 am
by 16561585
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

Re: OnMouseDown event on TIWChart does not work

Posted: Fri Jul 20, 2012 4:04 pm
by yeray
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.

Re: OnMouseDown event on TIWChart does not work

Posted: Wed Jul 25, 2012 4:53 am
by 16561585
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

Re: OnMouseDown event on TIWChart does not work

Posted: Thu Jul 26, 2012 3:19 pm
by yeray
Hi Stephen,

Great! Thanks for sharing! :D