reverse axis without reversing data on SurfaceGridSeries3D ?

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
Greg9504
Posts: 38
Joined: Fri Dec 06, 2013 4:51 pm

reverse axis without reversing data on SurfaceGridSeries3D ?

Post by Greg9504 » Fri Dec 06, 2013 5:59 pm

Hello,

I would like to have the X axis decrease in value on a 3D surface plot but I do not need (I think) to reverse the data.

I have the following grid information:
2D grid, YxX (Y rows, X Columns)
nX - number of points in X
nY - number of points in Y
dX - amount X increases
dY - amount Y increases
orgX - starting value of X at origin
orgY - starting value of Y at origin

On a 2D plot the origin is taken to be at the TOP LEFT.

The data values are stored in flat 1D array in column major format with origin at the top left, the array would would have values stored like:
[0,MaxY], [0,MaxY -1]...[0,MinY], [1,MaxY],[1,MaxY-1]...[1,MinY]... [MaxX,MaxY],[MaxX, MaxY -1]...[MaxX, MinY]
given
double[] datavalues;
datavalues[0] = [0,MaxY]
and
datavalues[end]=[MaxX,MinY]

The attached screen shot may help visualize this:
zmap_example.jpg
zmap_example.jpg (126.06 KiB) Viewed 14141 times
Here is what I have it looking like in LighningChart, I'm using the values to set the LightningChart Y axis (passed as Z in the code):
LightningChart
LightningChart
zmapinlighning.jpg (179.03 KiB) Viewed 14141 times
As you can see the LightningChart X axis starts at 2000000, I would like it to start at 2040000 and decrease to 2000000.

Here is my code:

Code: Select all

 public void CreateChart(int nX, int nY, double dx, double dy, double orgX, double orgY, float[] Z)
        {

            //Create new chart 
            m_chart = new LightningChartUltimate(LicenseKeys.LicenseKeyStrings.LightningChartUltimate);
            
            //Disable rendering, strongly recommended before updating chart properties
            m_chart.BeginUpdate();

            //Set 3D as active view
            m_chart.ActiveView = ActiveView.View3D;

            //Chart parent must be set
            m_chart.Parent = this;
            
            //Fill parent area with chart
            m_chart.Dock = DockStyle.Fill;

            //Chart name
            m_chart.Name = "Simple surface grid 3D chart";         

            //Set x-rotation
            m_chart.View3D.Camera.RotationX = 38;
            //Set transparent walls 
            List<WallBase> walls = m_chart.View3D.GetWalls();
            foreach (WallBase wall in walls)
            {
                wall.Material.DiffuseColor = Color.FromArgb(30, wall.Material.DiffuseColor);
                wall.SetGridStripColor1(Color.FromArgb(60, wall.GetGridStripColor1()));
                wall.SetGridStripColor2(Color.FromArgb(60, wall.GetGridStripColor2()));
            }
            //Lightning Chart coords, our X = their Z, our Y = their X, our Z = their Y on 3D plots
            m_chart.View3D.XAxisPrimary3D.SetRange(orgY, orgY + nY * dy);
            m_chart.View3D.ZAxisPrimary3D.SetRange(orgX, orgX + nX * dx);
            
            float[] fz = Z.Where(z => !Double.IsNaN(z)).ToArray();//filter out NaNs before getting min/max
            m_chart.View3D.YAxisPrimary3D.SetRange(fz.Min(), fz.Max());
            m_chart.View3D.YAxisPrimary3D.Reversed = true;//depths are positive values "Below Sea Level", so reverse

            //Add 3D surface grid
            SurfaceGridSeries3D gridSeries = new SurfaceGridSeries3D(m_chart.View3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
            gridSeries.ContourPalette = CreatePalette(gridSeries, fz.Min(), fz.Max());
            gridSeries.ContourLineType = ContourLineType.ColorLine;
            gridSeries.ContourLineWidth = 2;
            gridSeries.WireframeType = SurfaceWireframeType.None;
            gridSeries.Fill = SurfaceFillStyle.Paletted;
                        
            m_chart.View3D.SurfaceGridSeries3D.Add(gridSeries);                                  
            gridSeries.SmoothShading = true;            
            gridSeries.SetRangesXZ(orgY, orgY + nY * dy, orgX, orgX + nX * dx);
            gridSeries.SetSize(nY, nX);

            //Set Y values for nodes      
            //Lightning Chart coords, our X = their Z, our Y = their X, our Z = their Y on 3D plots
            for (int iNodeX = 0; iNodeX < nY; iNodeX++)
            {
                for (int iNodeZ = 0; iNodeZ < nX; iNodeZ++)
                {
                    gridSeries.Data[iNodeZ, iNodeX].Y = (Z[iNodeX*nY + iNodeZ]);//stored column major
                }
            }
            //Notify new values are ready
            gridSeries.InvalidateData();

            //Allow chart rendering
            m_chart.EndUpdate();
        }
Any ideas on how to accomplish this?
Thanks
Greg.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: reverse axis without reversing data on SurfaceGridSeries

Post by ArctionPasi » Fri Dec 06, 2013 6:58 pm

Hi Greg,

chart.View3D.XAxisPrimary3D.Reversed = true makes it start from the axis maximum value, and to run to axis minimum.
LightningChart Support Team, PT

Greg9504
Posts: 38
Joined: Fri Dec 06, 2013 4:51 pm

Re: reverse axis without reversing data on SurfaceGridSeries

Post by Greg9504 » Fri Dec 06, 2013 7:28 pm

Yes I tried that but then the plot ends up messed up, right now it is displaying how I think it should, just the axis values are reversed. I'll post a pic if what happens when I get back to my desktop.

Greg9504
Posts: 38
Joined: Fri Dec 06, 2013 4:51 pm

Re: reverse axis without reversing data on SurfaceGridSeries

Post by Greg9504 » Fri Dec 06, 2013 8:19 pm

First file shows the lightning chart next to a 2D plot of the data from another program. This is without the reversing the X axis.
no reverse
no reverse
both.jpg (167.31 KiB) Viewed 14136 times
With reversing the X axis (m_chart.View3D.XAxisPrimary3D.Reversed = true;)
reverse
reverse
bothXreversed.jpg (146.54 KiB) Viewed 14136 times

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: reverse axis without reversing data on SurfaceGridSeries

Post by ArctionPasi » Sat Dec 07, 2013 12:58 am

You'll need to reverse the series.Data filling, so that first column data Y values become last column data Y values and so on. Then I believe you get the equivalent order.

If the lights look awkward, change series.LightedSurface setting.
LightningChart Support Team, PT

Greg9504
Posts: 38
Joined: Fri Dec 06, 2013 4:51 pm

Re: reverse axis without reversing data on SurfaceGridSeries

Post by Greg9504 » Sat Dec 07, 2013 4:01 pm

Thanks... I finally figured out what I was doing wrong. After reversing the axis I changed the code to:

Code: Select all

            //Lightning Chart coords, our X = their Z, our Y = their X, our Z = their Y on 3D plots            
            for (int iNodeX = 0; iNodeX < nY; iNodeX++)
            {
                for (int iNodeZ = nX; iNodeZ > -1; iNodeZ--)
                {
                    gridSeries.Data[iNodeX, iNodeZ].Y = (Z[iNodeZ * nY + iNodeX]);//stored column major, Grid
                }
            }

But what I really needed to do was:

Code: Select all

            //Lightning Chart coords, our X = their Z, our Y = their X, our Z = their Y on 3D plots            
            for (int iNodeX = 0; iNodeX < nY; iNodeX++)
            {
                for (int iNodeZ = 0; iNodeZ < nX; iNodeZ++)
                {                   
                    gridSeries.Data[(nY-1) - iNodeX, iNodeZ].Y = (Z[iNodeZ * nY + iNodeX]);//stored column major, Grid
                }
            }

Now it displays as intended.
Thanks.
Greg.

Post Reply