Synchronize TDrawLineTools
Synchronize TDrawLineTools
Hi,
I have two TCharts displayed on the screen, each has a TDrawLineTool for drawing rectangles on the Chart. How can I synchronize two TDrawLineTools on TChart like the TeeChart demo example for synchronizing two cursors? For example, when a rectangle is added or resized on the 1st Chart, a rectangle will also be added and resized on the 2nd Chart at the same time. I tried the OnDraggedLine event to resize the rectangle on the 2nd Chart but it is only called after the rectangle on the 1st Chart has been dragged or resized. Is it possible to have the rectangle on the 2nd Chart moving or resizing at the same time when dragging the rectangle on the 1st Chart?
Thanks
Xia
I have two TCharts displayed on the screen, each has a TDrawLineTool for drawing rectangles on the Chart. How can I synchronize two TDrawLineTools on TChart like the TeeChart demo example for synchronizing two cursors? For example, when a rectangle is added or resized on the 1st Chart, a rectangle will also be added and resized on the 2nd Chart at the same time. I tried the OnDraggedLine event to resize the rectangle on the 2nd Chart but it is only called after the rectangle on the 1st Chart has been dragged or resized. Is it possible to have the rectangle on the 2nd Chart moving or resizing at the same time when dragging the rectangle on the 1st Chart?
Thanks
Xia
Re: Synchronize TDrawLineTools
Hi Xia,
Here is an example that, if I understood well, is doing what you've requested:
Here is an example that, if I understood well, is doing what you've requested:
Code: Select all
var DrawLineTool1, DrawLineTool2: TDrawLineTool;
AllowDrag: Boolean;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.AddSeries(TPointSeries.Create(self));
Chart1[0].FillSampleValues();
Chart2.AddSeries(CloneChartSeries(Chart1[0]));
Chart2[0].ColorEachPoint := true;
Chart1.Legend.Visible := false;
Chart2.Legend.Visible := false;
DrawLineTool1 := TDrawLineTool.Create(self);
DrawLineTool1.Style := dlRectangle;
DrawLineTool2 := CloneChartTool(DrawLineTool1, self) as TDrawLineTool;
Chart1.Tools.Add(DrawLineTool1);
Chart2.Tools.Add(DrawLineTool2);
DrawLineTool1.OnNewLine := NewLine;
DrawLineTool2.OnNewLine := NewLine;
DrawLineTool1.OnDragLine := DragLine;
DrawLineTool2.OnDragLine := DragLine;
Chart1.OnMouseDown := ChartMouseDown;
Chart2.OnMouseDown := ChartMouseDown;
end;
procedure TForm1.AssignLine(LineFrom, LineTo: TDrawLines; Index: Integer);
begin
LineTo.Line[Index].Assign(LineFrom.Line[Index]);
end;
procedure TForm1.NewLine(Sender: TObject);
begin
if Sender = DrawLineTool1 then
begin
DrawLineTool2.Lines.Add;
AssignLine(DrawLineTool1.Lines, DrawLineTool2.Lines, DrawLineTool1.Lines.Count-1);
Chart2.Refresh;
end
else //Sender = DrawLineTool2
begin
DrawLineTool1.Lines.Add;
AssignLine(DrawLineTool2.Lines, DrawLineTool1.Lines, DrawLineTool1.Lines.Count-1);
Chart1.Refresh;
end;
end;
procedure TForm1.DragLine(Sender: TObject);
begin
if AllowDrag then
if Sender = DrawLineTool1 then
begin
AssignLine(DrawLineTool1.Lines, DrawLineTool2.Lines, DrawLineTool1.Selected.Index);
Chart2.Refresh;
end
else
begin
AssignLine(DrawLineTool2.Lines, DrawLineTool1.Lines, DrawLineTool2.Selected.Index);
Chart1.Refresh;
end;
end;
procedure TForm1.ChartMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (DrawLineTool1.Clicked(X,Y) <> nil) or (DrawLineTool2.Clicked(X,Y) <> nil) then
AllowDrag := true
else
AllowDrag := false;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Synchronize TDrawLineTools
Hi Yeray,
Thanks for the example. It is very helpful. I have added codes to my program and I can add a rectangle on the 2nd Chart. But, there are some problems
1. Rectangle on the 2nd Chart is shown until the mouse released.
2. When dragging the rectangle on the 1st Chart for resizing, the rectangle on the 2nd Chart does not change and it resizes only after releasing mouse and then clicking on the rectangle.
I check the TChart User Guide and it said that OnDragLine is called when user has clicked a line and has begin dragging it and OnDraggedLine called when a line has been dragged to a new position, so I changed the code to set AllowDrag=true in OnDragLine and set AllowDrag=false in OnDraggedLine and then call AssignLine in the ChartMouseMove() function if AllowDrag==true. But it still does not work and it doesn't seem to call AssignLine in the ChartMouseMove function. Any suggestions?
Regards
Xia
Thanks for the example. It is very helpful. I have added codes to my program and I can add a rectangle on the 2nd Chart. But, there are some problems
1. Rectangle on the 2nd Chart is shown until the mouse released.
2. When dragging the rectangle on the 1st Chart for resizing, the rectangle on the 2nd Chart does not change and it resizes only after releasing mouse and then clicking on the rectangle.
I check the TChart User Guide and it said that OnDragLine is called when user has clicked a line and has begin dragging it and OnDraggedLine called when a line has been dragged to a new position, so I changed the code to set AllowDrag=true in OnDragLine and set AllowDrag=false in OnDraggedLine and then call AssignLine in the ChartMouseMove() function if AllowDrag==true. But it still does not work and it doesn't seem to call AssignLine in the ChartMouseMove function. Any suggestions?
Regards
Xia
Re: Synchronize TDrawLineTools
Hi Xia,
Excuse me, in the test application I assigned the OnMouseDown events at design time. Please, add the following at the end of OnCreate (I've modified the code above too):
Excuse me, in the test application I assigned the OnMouseDown events at design time. Please, add the following at the end of OnCreate (I've modified the code above too):
Code: Select all
Chart1.OnMouseDown := ChartMouseDown;
Chart2.OnMouseDown := ChartMouseDown;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Synchronize TDrawLineTools
Hi Yeray,
I have already added the OnMouseDown event at design time. If I understand correctly, the OnDragLine event is only called at the beginning of dragging (i.e when pressing the mouse down) and it will not response to mouse move with the left button pressed for resizing the rectangle.
Regards
Xia
I have already added the OnMouseDown event at design time. If I understand correctly, the OnDragLine event is only called at the beginning of dragging (i.e when pressing the mouse down) and it will not response to mouse move with the left button pressed for resizing the rectangle.
Regards
Xia
Re: Synchronize TDrawLineTools
Hi Xia,
I'm not sure to understand what problem do you have. Could you please try the attached application and tell me the exact steps I should do to reproduce the problem and/or what do you expect the application should do?
Thanks in advance.
I'm not sure to understand what problem do you have. Could you please try the attached application and tell me the exact steps I should do to reproduce the problem and/or what do you expect the application should do?
Thanks in advance.
- Attachments
-
- SynchronDrawLine.zip
- (1.93 KiB) Downloaded 541 times
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Synchronize TDrawLineTools
Hi Yeary,
Thanks for the application code. I have created a project using your code, but I have to change accordingly since I am using CodeGear C++ Builder. I have the same problems.
1. When you resize the rectangle on the Chart1 by dragging the corner of the rectangle, the rectangle on the Chart2 does not resize until you release mouse button, and click and drag the rectangle1 again.
2. During resizing the rectangle on the Chart1, the shape of rectangle1 changes when dragging the mouse, but the rectangle on the Chart 2 does not change at all. I would like to see both rectangles change size when dragging the mouse.
Let me know if need further clarification.
Regards
Xiabing
Thanks for the application code. I have created a project using your code, but I have to change accordingly since I am using CodeGear C++ Builder. I have the same problems.
1. When you resize the rectangle on the Chart1 by dragging the corner of the rectangle, the rectangle on the Chart2 does not resize until you release mouse button, and click and drag the rectangle1 again.
2. During resizing the rectangle on the Chart1, the shape of rectangle1 changes when dragging the mouse, but the rectangle on the Chart 2 does not change at all. I would like to see both rectangles change size when dragging the mouse.
Let me know if need further clarification.
Regards
Xiabing
Re: Synchronize TDrawLineTools
Hi Xiabing,
Maybe you forgot something because I can't see this effect. Please find attached the example project made in C++Builder 2010 & TeeChart Pro 8.06.
Maybe you forgot something because I can't see this effect. Please find attached the example project made in C++Builder 2010 & TeeChart Pro 8.06.
- Attachments
-
- SynchronDrawLine2.zip
- (6.91 KiB) Downloaded 537 times
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Synchronize TDrawLineTools
Hi Yeary,
Thanks for the example files. It has the same problems with TChart V8.02. But after upgrading to TChart V8.06, the program works fine, i.e. both Rectangles can be resized at the same time. So I think the problem is related to TChart V8.02.
However, I have two other projects which worked fine with TChart V8.02. After upgrading to V8.06, they both have some problems. One of the project uses TPointSeries, the program gives an error message "Invalid floating point operation" at the code below
Series1->YValue[0] = Series2->YValue[2];
The other project uses TColorGridSeries, the program gives an error message "Access violation at address ..." when filling in data using Dynamic array as below
void __fastcall TMDIChild::FillSeries()
{
DynamicArray<double> X, Y, Z;
int x, y, TotalCount;
try
{
TotalCount = 100;
X.Length = TotalCount;
Z.Length = TotalCount;
Y.Length = TotalCount;
for (y=0; y<10; y++ )
for ( x=0; x<10; x++ )
{
// fill in data
X[y*10+x] = x+1;
Z[y*10+x] = y+1;
Y[y*10+x] = x+y; // test data
}
}
__finally
{
Series->XValues->Value = (TChartValues)(X);
Series->XValues->Count = TotalCount;
Series->XValues->Modified = true;
Series->ZValues->Value = (TChartValues)(Z); //error message shown here
Series->ZValues->Count = TotalCount;
Series->ZValues->Modified = true;
Series->YValues->Value = (TChartValues)(Y);
Series->YValues->Count = TotalCount;
Series->YValues->Modified = true;
}
}
Both problems seem to do with TChartValues. Are there any known issues with TChartValue when upgrading to V8.06? Your help is very much appreciated.
Regards
Xia
Thanks for the example files. It has the same problems with TChart V8.02. But after upgrading to TChart V8.06, the program works fine, i.e. both Rectangles can be resized at the same time. So I think the problem is related to TChart V8.02.
However, I have two other projects which worked fine with TChart V8.02. After upgrading to V8.06, they both have some problems. One of the project uses TPointSeries, the program gives an error message "Invalid floating point operation" at the code below
Series1->YValue[0] = Series2->YValue[2];
The other project uses TColorGridSeries, the program gives an error message "Access violation at address ..." when filling in data using Dynamic array as below
void __fastcall TMDIChild::FillSeries()
{
DynamicArray<double> X, Y, Z;
int x, y, TotalCount;
try
{
TotalCount = 100;
X.Length = TotalCount;
Z.Length = TotalCount;
Y.Length = TotalCount;
for (y=0; y<10; y++ )
for ( x=0; x<10; x++ )
{
// fill in data
X[y*10+x] = x+1;
Z[y*10+x] = y+1;
Y[y*10+x] = x+y; // test data
}
}
__finally
{
Series->XValues->Value = (TChartValues)(X);
Series->XValues->Count = TotalCount;
Series->XValues->Modified = true;
Series->ZValues->Value = (TChartValues)(Z); //error message shown here
Series->ZValues->Count = TotalCount;
Series->ZValues->Modified = true;
Series->YValues->Value = (TChartValues)(Y);
Series->YValues->Count = TotalCount;
Series->YValues->Modified = true;
}
}
Both problems seem to do with TChartValues. Are there any known issues with TChartValue when upgrading to V8.06? Your help is very much appreciated.
Regards
Xia
Re: Synchronize TDrawLineTools
Hi Xia,
1. PointSeries. I've made a new application, dropped a chart on the form, two point series in it and the following code and everything works as expected:
2. Similar to 1, I've created the ColorGrid series at design time and your code seems to work fine.
Could you please check that your IDE and your project don't have old TeeChart references at library and search paths?
If you still have problems with it, please attach a simple example project we can run as-is to reproduce the problem here.
1. PointSeries. I've made a new application, dropped a chart on the form, two point series in it and the following code and everything works as expected:
Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Chart1->View3D = false;
Series1->FillSampleValues(5);
Series2->FillSampleValues(5);
Series1->YValue[0] = Series2->YValue[2];
}
Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DynamicArray<double> X, Y, Z;
int x, y, TotalCount;
try
{
TotalCount = 100;
X.Length = TotalCount;
Z.Length = TotalCount;
Y.Length = TotalCount;
for (y=0; y<10; y++ )
for ( x=0; x<10; x++ )
{
// fill in data
X[y*10+x] = x+1;
Z[y*10+x] = y+1;
Y[y*10+x] = x+y; // test data
}
}
__finally
{
Series1->XValues->Value = (TChartValues)(X);
Series1->XValues->Count = TotalCount;
Series1->XValues->Modified = true;
Series1->ZValues->Value = (TChartValues)(Z); //error message shown here
Series1->ZValues->Count = TotalCount;
Series1->ZValues->Modified = true;
Series1->YValues->Value = (TChartValues)(Y);
Series1->YValues->Count = TotalCount;
Series1->YValues->Modified = true;
}
}
If you still have problems with it, please attach a simple example project we can run as-is to reproduce the problem here.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Synchronize TDrawLineTools
Hi Yeary,
Thanks. You are right that I need to change the include and lib paths to new version.
TDrawLineTools synchronisation works nicely for two TCharts. A drawback of this synchronisation when dragging the rectangle is that it is a bit slow for TColorGridSeries when having over 500x500 pixels. How can I improve plot speed for TColorGridSeries? I read the article for real-time plotting but it didn't mention TColourGridSeries.
One other issue is that horizontal Grid function seems not working for TColorGridSeries in the new version 8.06. I tried ColorGrid example in New Feature Demo software. It only plots vertical grid but not horizontal grid.
Regards
Xia
Thanks. You are right that I need to change the include and lib paths to new version.
TDrawLineTools synchronisation works nicely for two TCharts. A drawback of this synchronisation when dragging the rectangle is that it is a bit slow for TColorGridSeries when having over 500x500 pixels. How can I improve plot speed for TColorGridSeries? I read the article for real-time plotting but it didn't mention TColourGridSeries.
One other issue is that horizontal Grid function seems not working for TColorGridSeries in the new version 8.06. I tried ColorGrid example in New Feature Demo software. It only plots vertical grid but not horizontal grid.
Regards
Xia
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Synchronize TDrawLineTools
Hi Xia,
A 500x500 grid is quite a big grid it doesn't surprise me that it is slow. For optimizing speed in such series I recommend you to avoid setting IrregularGrid=True whenever it's possible. For more information on how this property works please read this thread.A drawback of this synchronisation when dragging the rectangle is that it is a bit slow for TColorGridSeries when having over 500x500 pixels. How can I improve plot speed for TColorGridSeries? I read the article for real-time plotting but it didn't mention TColourGridSeries.
I could reproduce this here and added the defect to the list (TV52014524) to be fixed for future releases.One other issue is that horizontal Grid function seems not working for TColorGridSeries in the new version 8.06. I tried ColorGrid example in New Feature
Demo software. It only plots vertical grid but not horizontal grid.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Synchronize TDrawLineTools
Hi Narcis,
Thanks for your reply.
I have already set IrregularGrid=false. TColorGridSeries is very powerful data series for 2D image display and it is just a bit slow for a higher resolution image.
For the TDrawLineTool, I would like to handle differently when dragging the entire rectangle for reposition or dragging the corners of the rectangle for resizing. Is there anyway to know whether the start or end point is dragged or the entire shape is dragged for reposition.
Regards
Xia
Thanks for your reply.
I have already set IrregularGrid=false. TColorGridSeries is very powerful data series for 2D image display and it is just a bit slow for a higher resolution image.
For the TDrawLineTool, I would like to handle differently when dragging the entire rectangle for reposition or dragging the corners of the rectangle for resizing. Is there anyway to know whether the start or end point is dragged or the entire shape is dragged for reposition.
Regards
Xia
Re: Synchronize TDrawLineTools
Hi Xia,
Yes, you could use the DrawLineTool rectangles "StartHandle" and "EndHandle" to see if the mouse was clicked in the resizing points or not:
Yes, you could use the DrawLineTool rectangles "StartHandle" and "EndHandle" to see if the mouse was clicked in the resizing points or not:
Code: Select all
procedure TForm1.ChartMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var tmpTool: TDrawLine;
begin
tmpTool:=DrawLineTool1.Clicked(X,Y);
if tmpTool = nil then
tmpTool:=DrawLineTool2.Clicked(X,Y);
if (tmpTool <> nil) then
if PtInRect(tmpTool.StartHandle,Point(X,Y)) or PtInRect(tmpTool.EndHandle,Point(X,Y)) then
begin
AllowDrag := true;
AllowMove := false;
end
else
begin
AllowDrag := false;
AllowMove := true;
end
else
begin
AllowDrag := false;
AllowMove := false;
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Synchronize TDrawLineTools
Hi Yeary,
Thanks. It works.
Regarding the grid on/off bug for TColorGridSeries, will this be fixed in next 3-6 months? If not, do you have a work-around solution?
Regards
Xiabing
Thanks. It works.
Regarding the grid on/off bug for TColorGridSeries, will this be fixed in next 3-6 months? If not, do you have a work-around solution?
Regards
Xiabing