Author |
Topic  |
|
Tobias J
10 Posts |
Posted - 02 Aug 2006 : 07:28:18
|
Hello,
I have created a chart with one x-axis and two y-axes (one y-axis on the left side and the other on the right side). Everything works fine until I create and add a Grid for the right y-axis like this:
Grid yGridRight = new Grid(xAxis, yAxisRight, ChartObj.Y_AXIS, ChartObj.GRID_MAJOR); AddChartObject(yGridRight);
When I do this, the x-axis for some reason gets dislocated. Before I create and add the Grid, the left y-axis has a minimum limit of 0, while the right y-axis has a minimum limit of 1. Both y-axes are set to intercept the x-axis at those locations, which works fine at first. After I have created the grid though, the x-axis gets located below its original location. The new x-axis location apparently corresponds to 0 on the RIGHT axis instead of corresponding to 0 on the LEFT y-axis like it used to be. I have been trying to fix this manually by using
xAxis.SetAxisIntercept(yAxisLeft.GetAxisMin())
but without success.
The method description for SetAxisIntercept reads as follow: “Sets the intercept of this axis with the orthogonal axis in physical coordinates”. This however does not take into account that multiple orthogonal axes (i.e. y-axes) may be used. This is probably why the x-axis gets dislocated in the first place; the method doesn’t seem to know which y-axis to ”attach” the x-axis to.
I would be grateful if you could present a solution to this problem.
Regards, Tobias |
|
quinncurtis
1164 Posts |
Posted - 02 Aug 2006 : 09:02:29
|
The x-axis does not attach itself to a y-axis. When you specify the y-intercept of the x-axis, you are specifying the x-axis position with respect to the physical coordinate system that the x-axis resides in. You do not even need a y-axis and you can still specify the y-intercept of the x-axis.
It is not clear if you are using one, or two, different physical coordinate system, each one associate with a different y-axis. If you ARE using two different coordinate systems, make sure that the two axes that you specify in the Grid constructor use the SAME coordinate system, not one from each. If you want the grid for the right y-axis you should create the x-axis using the coordinate system used by the right y-axis.
Something else must be going on that you are not showing. The best thing to do is to create the simplest possible example program that reproduces the problem. We took our example program SimpleLinePlots.SimpleLineAndScatterPlot and in a few seconds modified to do what you describe and it seems to work fine. See how it works for you.
LinearAxis xAxis = new LinearAxis(pTransform1, ChartObj.X_AXIS);
chartVu.AddChartObject(xAxis);
LinearAxis yAxis = new LinearAxis(pTransform1, ChartObj.Y_AXIS);
chartVu.AddChartObject(yAxis
// Added these lines
LinearAxis yAxis2 = new LinearAxis(pTransform1, ChartObj.Y_AXIS);
yAxis2.SetAxisIntercept(xAxis.GetAxisMax());
chartVu.AddChartObject(yAxis2);
xAxis.SetAxisIntercept(yAxis.GetAxisMin());
// End of addition
.
.
.
// Modified these lines to use yAxis2
Grid xgrid = new Grid(xAxis, yAxis2,ChartObj.X_AXIS, ChartObj.GRID_MAJOR);
chartVu.AddChartObject(xgrid);
Grid ygrid = new Grid(xAxis, yAxis2,ChartObj.Y_AXIS, ChartObj.GRID_MAJOR);
chartVu.AddChartObject(ygrid);
// End of modification |
 |
|
Tobias J
10 Posts |
Posted - 03 Aug 2006 : 06:18:37
|
Thanks for the really quick reply and for clarifying some things. I am indeed using different coordinate systems for the two y-axes, which most likely is what causes the problems. The x-axis and the left y-axis are using the same coordinate system while the right y-axis is using a different one.
That brings up another question. I want the y-axes to have different scales, for example 0-100 on the right y-axis and 10-20 on the left one. If I am not mistaken, that means I must use different coordinate systems for the y-axes. Am I required to create a second x-axis using the same coordinate system as the right y-axis for the grid functionality to work?
Regards, Tobias
|
Edited by - Tobias J on 03 Aug 2006 06:20:15 |
 |
|
quinncurtis
1164 Posts |
Posted - 03 Aug 2006 : 08:47:31
|
Yes, if you want a grid for the right y-axis, you need an x-axis in the same coordinate system as the right y-axis.
That is why we suggested that instead of creating the x-axis with the coordinate system of the left y-axis, you create the x-axis using the coordinate system of the right. It sounds like you intended for the x-scale part of the coordinate system to be the same for both y-axes, so it really doesn't matter.
If you don't want to do that, just create another x-axis in the coordinate system of the right y-axis and either place it at the top of the graph, or disable it using (OBJECT_ENABLE_NODRAW) as below so that it is defined but doesn't get drawn to the screen.
LinearAxis xAxis2 = new LinearAxis(pTransform2, ChartObj.X_AXIS); xAxis2.ChartObjEnable = ChartObj.OBJECT_ENABLE_NODRAW; chartVu.AddChartObject(xAxis2);
|
 |
|
Tobias J
10 Posts |
Posted - 03 Aug 2006 : 11:24:44
|
I do want to the x-scale part to be the same for both y-axes. Looking at my previous posts I see that I haven’t mentioned that I would like to display grids for BOTH y-axes. I haven’t tried the code that you displayed in your last post, with a second hidden xAxis, but that will work for sure.
One more question, just out of curiosity: would it be possible to display grids for both y-axes using only one x-axis (again, the y-axes will have different limits so I assume they require two different coordinate system)?
Regards, Tobias
|
 |
|
quinncurtis
1164 Posts |
Posted - 03 Aug 2006 : 12:28:03
|
As was previously discussed, a grid requires references to both an x- and y-axis, in the same coordinate system. It uses the tick mark placement of one axis for placing the grid lines, and uses the length of the orthagonal axis as the measure of how long to draw the grid line. So you can't draw a grid with a reference to only one axis. |
 |
|
Tobias J
10 Posts |
Posted - 04 Aug 2006 : 03:51:42
|
I meant if it would be possible to create both y-grids from a shared xAxis like below:
LinearAxis xAxis = new LinearAxis(pTransform1, ChartObj.X_AXIS); chartVu.AddChartObject(xAxis);
LinearAxis yAxis1 = new LinearAxis(pTransform1, ChartObj.Y_AXIS); chartVu.AddChartObject(yAxis1);
LinearAxis yAxis2 = new LinearAxis(pTransform2, ChartObj.Y_AXIS); yAxis2.SetAxisIntercept(xAxis.GetAxisMax()); chartVu.AddChartObject(yAxis2);
xAxis.SetAxisIntercept(yAxis.GetAxisMin());
Grid ygrid1 = new Grid(xAxis, yAxis1,ChartObj.Y_AXIS, ChartObj.GRID_MAJOR); chartVu.AddChartObject(ygrid);
Grid ygrid2 = new Grid(xAxis, yAxis2,ChartObj.Y_AXIS, ChartObj.GRID_MAJOR); chartVu.AddChartObject(ygrid);
From what I can understand, ygrid2 would not work well because xAxis and yAxis2 have different coordinate systems. Therefore, I must create a second xAxis like you mentioned above:
LinearAxis xAxis2 = new LinearAxis(pTransform2, ChartObj.X_AXIS); xAxis2.ChartObjEnable = ChartObj.OBJECT_ENABLE_NODRAW; chartVu.AddChartObject(xAxis2)
and instead create yGrid2 as below:
Grid ygrid2 = new Grid(xAxis2, yAxis2,ChartObj.Y_AXIS, ChartObj.GRID_MAJOR); chartVu.AddChartObject(ygrid);
Would this be the only way to make it work (i.e. multiple x-axes)?
|
Edited by - Tobias J on 04 Aug 2006 07:25:32 |
 |
|
quinncurtis
1164 Posts |
Posted - 04 Aug 2006 : 09:14:37
|
We understand exactly what you mean. Both axes referenced in the grid constructor must use the same coordinate system. You must create a second x-axis, using the same coordinate system as the second y-axis. |
 |
|
|
Topic  |
|
|
|