|
severe SurfaceChart bug (chart is distorted) |
Posted by Lofi on Dec-06-2009 02:54 |
|
i never got a good looking surface chart except with the sample data from the help file. but the more data i put into chartdirector, the uglier the chart gets. i reduced this to being most probably a bug in chartdirector.
attached you can see an example how it looks like when you put the following numbers into the surfacechart source code from the help file:
double[] dataX = { 0, 100, 0, 100};
double[] dataY = { 0, 100, 100, 10};
double[] dataZ = { 1, 1, 1, 1};
i also added the sample source.
is there a solution to this?
thanks in advance!
|
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Lofi on Dec-06-2009 03:01 |
|
another bug besides the chart being wrong is if you use eg the following numbers in the same source:
double[] dataX = { 0, 1, 0, 1 };
double[] dataY = { 0, 1, 1, 1 };
double[] dataZ = { 0, 1, 0, 0 };
there are often those zig-zag lines. is there a way to get rid of them?
by the way, is it possible to rotate the chart with the mouse?
|
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Peter Kwan on Dec-06-2009 16:52 |
|
Hi Lofi,
It seems in both cases, the charts reflect your data very accurately. It does illustrate two of the limitations/features of the surface chart.
(a) Because computations in a computer is not infinitely accurate (the double precision floating point number only have 64-bit precision), so the computed data values are not infinitely accurate. The accuracy is around 99.9999999999999% (or something like this). Normally, this will not cause any visible issue in graphics, but in special cases, even 0.000000000001% inaccuracy can be visible.
(b) In ChartDirector surface chart, the surface is computed one rectangular cell at a time. The cell density is configurable (default is around 50 x 50). So if scatter data points are used, and the convex hull of the data points are not xy rectangular (like in your second chart, which is triangular), some borders may be shown as "zig-zag" shape. (Some people will try to add some "dummy points" at the 4 corners of the rectangle, to make sure the convex hull of the points are rectangular
In your first chart, the z values are constant (1, 1, 1, 1). After computation, due to the finite accuracy of ChartDirector, the z values for the entire surface is 0.9999999999999998 - 1.0000000000000002. Because your code have not specified the z-axis range, so ChartDirector uses a z-axis range of 0.9999999999999998 - 1.0000000000000002. Thus even the 0.0000000000000002 difference becomes visible in the chart.
The above phenomena can only occur if the z values are constant. If they are non-constant (say the z values are 1, 1, 1, 1.00001), the error of 0.00000000000001% will become invisible, because they are negligibly small compared to the range of z-values.
Alternatively, you can set the z-axis scale (say c.zAxis().setLinearScale(0, 2, 1)). This will also cause the 0.0000000000000002 error to become invisible.
If your actual data can be a constant, you may want to check this special case, and set the z-axis scale with your own code.
In your second chart, the chart accurately reflect your data. The zig-zag border is because of (b) above.
If you have some real data, and you think the chart does not look nice, may be you can show me what are your real data, and what is the resulting chart. A real chart does not necessarily look nice. It depends on your data. The important thing is that the chart should reflect your data accurately (eg. to within 99.9999999999999%).
Also, the ChartDirector surface chart by default uses smooth surface interpolation. This may not be suitable for all actual data. Some data are by their nature non-smooth. If smooth interpolation is used, ChartDirector will nevertheless try to fit a smooth surface to the data, and the shape may become strange. This is configurable using SurfaceChart.setInterpolation. If smooth interpolation is not suitable, you may try linear interpolation.
Hope this can help.
Regards
Peter Kwan |
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Lofi on Dec-07-2009 12:34 |
|
Hello Peter,
thanks a lot for your detailed answer!
it explains the issue perfectly. however, i can't explain this to a customer, so i'll create a workaround using your information.
one other question: is it possible to create a 3d chart with only the x/y/z points without connecting them, ie without creating a surface? and what's the preferred way to rotate the 3d chart dynamically? so far i've created 3 jspinner components which range from 0..359. if there's a better solution, please let me know.
again: thank you very much!
Lofi |
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Peter Kwan on Dec-07-2009 14:36 |
|
Hi Lofi,
For the (x, y, z) points, currently ChartDirector does not have a chart type for 3D scatter chart. You may try to do this as follows:
(a) Use ChartDirector to create a 3D surface chart with no surface. So it is just a plot regions with 3 walls and grid lines. You may need to set up the axes scale with your own code.
(b) Compute what would be the position of the (x, y, z) point as projected on the "canvas" (with is 2D on the computer screen). The code itself should be very short. However, it may need some detail understanding of 3D geometry to derived that short code.
(c) Once you have computed the (x, y) project on the screen, you may use the DrawArea functions to draw them on the canvas.
For rotation, using 3 spin buttons is one possible method. If you want, you can also create a user interface to let the user drags on the screen.
In case you are not aware, it is possible to control 3D rotation by dragging along two axes only (not by one single drag, but by a sequence of drags). For example, the "Euler angles" represent arbitrary 3D rotations as a three rotations along two axes only. See "http://en.wikipedia.org/wiki/Euler_angles". So it is completely feasible to use dragging on a 2D surface to control 3D rotations.
When the user drags on the chart surface, you would need to update the elevation, rotation and twist angles based on how the user drags the mouse, the redraw the chart. (I do not have the formula on how to update the elevation, rotation and twist angles based on the dragging. You would need to derived it using 3D geometry.)
Hope this can help.
Regards
Peter Kwan |
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Lofi on Dec-08-2009 14:36 |
|
hello Peter,
thanks again for your help. we'll use jspinner now to rotate, but hope that chartdirector gets the 3d rotating feature in a later release, it is very essential for 3d charts in my opinion. we tried several charting libraries before we decided to buy chartdirector. the 3d rotation is one of the main features that we'd need and which a competition library was superior in (because it had that feature). however, i encountered a severe bug in that competition library and it took the support 1 week to reply and another 4 weeks to fix it. so that library wasn't an option for us. so we decided to use chartdirector because of it's excellent support.
keep up the good support!
best regards
Lofi |
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Lofi on Dec-12-2009 18:08 |
|
hello Peter,
i have given up on creating a meaningful chart with chartdirector out of our real data. so i thought maybe you can come up with an idea of how to represent these data in 3d with chartdirector:
double[] dataX = { 140,143,184,201,209,215};
double[] dataY = { 300,300,340,340,360,360};
double[] dataZ = { 477,504,531,560,586,612};
the data aren't xy rectangular, and adding additional data to get rid of the zigzag-lines isn't an option for us, unfortunately.
i'd appreciate a suggestion of yours. the data have to be displayed with linear interpolation.
thanks in advance!
Lofi
|
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Peter Kwan on Dec-14-2009 17:32 |
|
Hi Lofi,
For gridded data (data points that falls on a rectangular grid), it is obvious where is the border of the data.
For scattered data (data points are the arbitrarily distsributed), it is not obvious where the border is. ChartDirector currently will use the "convex hull" of the points as the border. The border may not be aligned with the x or y axis. However, currently ChartDirector can only compute the surface one rectangular cell at a time. So the border may look "stair case".
For your scatter data, it is a thin strip with some twisting. Because it is thin, the border effects may become large compared to the thickness of the strip.
The stair case artifact may be reduced by asking ChartDirector to use finer cells. I have attached two charts, one using 400 x 400 cells, and one using 800 x 800 cells. You can see the stair case effect is reduced. (I think the default is around 50 x 50.)
Hope this can help.
Regards
Peter Kwan
|
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Labib on Sep-04-2016 17:21 |
|
How to change the cell size? |
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Labib on Sep-05-2016 07:11 |
|
Oh, sorry, i mean cell density. The chart looks smoother in your 400 x 400 and 800 x 800 cells. Thank you. |
Re: severe SurfaceChart bug (chart is distorted) |
Posted by Peter Kwan on Sep-05-2016 23:44 |
|
Hi Labib,
The API is SurfaceChart.setInterpolation. For example:
c.setInterpolation(400, 400, false);
Hope this can help.
Regards
Peter Kwan |
|