Relating point clicked and axis
Posted: Thu Mar 27, 2008 6:43 pm
I am drawing polygons on the ColorGridSeries chart and am trying to understand the connection between the X/Y values obtained in the Mouse Down event and the X/Z values in the Chart1.Series.AddXYZ method. As I add data points to the plot using the AddXYZ method, I want to change the values of points if I determine they are inside the polygons that I drew earlier…say, set them to zero.
So that you know, I set IrregularGrid = False when initializing the plot. I am setting my own axis labels by calling Chart1.Axes.Left.Items.Clear and Chart1.Axes.Bottom.Items.Clear, then add my own axis labels. I am not sure if this is necessary, but there was a bug in the plot code some time ago that caused zooming and panning to redraw REAL slow. Any ways I do not think that is important right now, just wanted to mention it.
In the Mouse Down event, I use the following code to get the index of the clicked point on the X and Z axis:
// X and Y are from the Chart1MouseDown entry point
k := Chart1.Series[0].Clicked(X, Y);
r := k div Chart1.Series.NumZValues;
c := k mod Chart1.Series.NumZValues;
This seems to work just fine. When I use r and c to calculate my axis values with my ScaleMul and ScaleOff it all works fine. For example:
My_X := r * xScaleMul + xScaleOff;
My_Y := c * zScaleMul + zScaleOff ;
Later in my code I add the data points to the plot as follows:
// DblImageData is a 2D array of points to generate the image.
For i := 0 to High(DblImageData) do
For j := 0 to High(DblImageData[0]) do
begin
p.x := i;
p.y := j
// wn_PnPoly checks to see if point p is inside the polygon formed
// using points in Polygon_Point_List
if (wn_PnPoly(p, Polygon_Point_List) <> 0) then
DblImageData[i,j] := 0;
Chart1.Series.AddXYZ(i, DblImageData[i,j], j);
end;
I can see the polygons appear on the plots, but not in the place I drew them. They appear to be upside down and flipped. It is as if the data is not added using the bottom left point as 0,0.
Can you explain what I am doing wrong?
Thanks in advance.
So that you know, I set IrregularGrid = False when initializing the plot. I am setting my own axis labels by calling Chart1.Axes.Left.Items.Clear and Chart1.Axes.Bottom.Items.Clear, then add my own axis labels. I am not sure if this is necessary, but there was a bug in the plot code some time ago that caused zooming and panning to redraw REAL slow. Any ways I do not think that is important right now, just wanted to mention it.
In the Mouse Down event, I use the following code to get the index of the clicked point on the X and Z axis:
// X and Y are from the Chart1MouseDown entry point
k := Chart1.Series[0].Clicked(X, Y);
r := k div Chart1.Series.NumZValues;
c := k mod Chart1.Series.NumZValues;
This seems to work just fine. When I use r and c to calculate my axis values with my ScaleMul and ScaleOff it all works fine. For example:
My_X := r * xScaleMul + xScaleOff;
My_Y := c * zScaleMul + zScaleOff ;
Later in my code I add the data points to the plot as follows:
// DblImageData is a 2D array of points to generate the image.
For i := 0 to High(DblImageData) do
For j := 0 to High(DblImageData[0]) do
begin
p.x := i;
p.y := j
// wn_PnPoly checks to see if point p is inside the polygon formed
// using points in Polygon_Point_List
if (wn_PnPoly(p, Polygon_Point_List) <> 0) then
DblImageData[i,j] := 0;
Chart1.Series.AddXYZ(i, DblImageData[i,j], j);
end;
I can see the polygons appear on the plots, but not in the place I drew them. They appear to be upside down and flipped. It is as if the data is not added using the bottom left point as 0,0.
Can you explain what I am doing wrong?
Thanks in advance.