ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Moving ScatterCharts Point
Posted by Damla B on Mar-07-2019 14:50
Hi,

I have 3DScatterChart. I want to move the points of this chart only in z axis. For now, I can change it, however I can not calculate real z value. I am using, getChartMouseY mehtod to get the last mouse position and try to understand y position change. With this differentiate ratio, I am trying to find new z value. But it does not work.

Now I have;

3DScatterChart point  xValue,yValue,zValue and MouseX, MouseY positions.
New point xValue,yValue and MouseX,MouseY positions. How can I find the z value and change the chart ?

Many Thanks,

  Re: Moving ScatterCharts Point
Posted by Peter Kwan on Mar-07-2019 22:58
Hi Damla B,

From my understanding, you want to obtain the unknown value zzz, so that the data point (xValue, yValue, zzz) is at pixel coordinate (mouseX, mouseY). Mathematically, this may not be possible. How do you known that the (mouseX, mouseY) must be somewhere on (xValue, yValue, zzz)? May be no such value zzz exist?

For your case, one method to work around is to find zzz that is nearest to (mouseX, mouseY). This can be achieved by testing several z values to see which is nearest to (mouseX, mouseY). For example, you can use simple binary iteration, and very quickly it will converge to the nearest point. (You can use ThreeDChart::getXCoor and ThreeDChart::getYCoor to compute the pixelX and pixelY given the (xValue, yValue, zValue). You can then determine the distance between (pixelX, pixelY) and (mouseX, mouseY).) See:

https://www.advsofteng.com/doc/cdcpp.htm#ThreeDChart.getXCoor.htm
https://www.advsofteng.com/doc/cdcpp.htm#ThreeDChart.getYCoor.htm

Hope this can help.

Regards
Peter Kwan

  Re: Moving ScatterCharts Point
Posted by Damla B on Mar-11-2019 14:37
Attachments:
Hi Peter,

I tried your suggestion but I could not be successful. Maybe I do something wrong. In the below you can see the chart I have. The green point ( x= 100, y = 0 , z = 0.25) I would like to move. When I press the mouse left click, I should move the point between z range (0.05-0.40). However I could not do it.

When I first press the point, I can get mouseX and mouseY positions. When I release the mouse, I can also get last mouseX and mouseY positions. I tried to compared these delta mouse X position and delta mouse Y position with delta Z value. However, I could not relate them.

Do you think is it possible to move point and change z value in data set?
scatterchart point move.png

  Re: Moving ScatterCharts Point
Posted by Damla B on Mar-11-2019 21:56
Hello again,

I would like to add that I try to getXCoor(x,y,z) and getYCoor(x2,y2,z2) values to understand the relationship between mouseXCoordinate and mouseYCoordinate but for 3DScatter chart getXCoor and getYCoor methods return 0. Do I do something wrong?

ThreeDScatterChart * c_min_scatter = new ThreeDScatterChart(720,600);

    c_min_scatter ->setPlotRegion(330, 290, 360, 360, 270);

    c_min_scatter ->addScatterGroup(DoubleArray(dataX, dataXLength),
                        DoubleArray(dataY, dataYLength),
                        DoubleArray(dataZ, dataXLength * dataYLength));

int xCoor  = c_min_scatter->getXCoor(6000.0,100.0,0.09);
int yCoor  = c_min_scatter->getYCoor(6000.0,100.0,0.09);

  Re: Moving ScatterCharts Point
Posted by Peter Kwan on Mar-11-2019 22:41
Hi Damia,

By default, ChartDirector will automatically determine the axis scale based on all the data points. For your case, your code calls addScatterGroup. However, ChartDirector cannot know if it already includes all your data, or if there wil be another addScatterGroup later to add more data. As ChartDirector does not know if it has all the data or not, it will not compute the axis scale at this stage, and so it does not know what are the pixel coordinates of any (x, y, z) point.

That's why getXCoor and getYCoor must be called only after displaying the chart, or only after calling BaseChart.layout, which tells ChartDirector all the data have already been entered. See:

https://www.advsofteng.com/doc/cdnet.htm#ThreeDChart.getXCoor.htm
https://www.advsofteng.com/doc/cdnet.htm#ThreeDChart.getYCoor.htm

For your case, please add c_min_scatter->layout(); before calling getXCoor and getYCoor,

Hope this can help.

Regards
Peter Kwan

  Re: Moving ScatterCharts Point
Posted by Damla B on Mar-11-2019 22:50
Hi Peter,

layout() helps to work. Many thanks!

  Re: Moving ScatterCharts Point
Posted by Peter Kwan on Mar-11-2019 23:49
Hi Damia,

For your case, I would think the outline of the code should be like:

(a) You have a point at (x, y, z) to be dragged. The pixel coordinate (px, py) of the center of the point can be obtained using getXCoor and getYCoor.

(b) Your moves for (dx, dy). So the point should move to (px + dx, px + dy). The problem is to find z2 so that (x, y, z2) is nearest to (px + dx, px + dy).

To do this, one simple method is just to try various values of z2 to obtain the nearest one. In the simplest case, you can just try z2 between 0.05 to 0.4 with an increment of 0.001 to determine the nearest point. A better method is to use binary iteration to try the various z2 values, which is exponentially faster than linear search.

Hope this can help.

Regards
Peter Kwan

  Re: Moving ScatterCharts Point
Posted by Damla B on Mar-12-2019 18:16
Hi Peter,

Thank you so much for your valuable answers. It works :)