Profile Picture

aligning NCartesianCharts

Posted By Michael Hayford 14 Years Ago
Author
Message
Michael Hayford
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
I have a chart configuration I'm trying to produce in which I have a GridSurfaceSeries of data that I want to display as a contour chart and two line charts that display orthogonal slices of data from the grid series. I would like the actual position and length of the line chart axes to align with the side of the contour chart. I think I've gotten myself completely confused in the process.

The attached jpg file shows what I have with the red lines showing the points on the adjacent charts that I'd like to line up. For the purpose of this example, I have tried to keep the settings I used as simple as possible. All 3 charts have chart.BoundsMode = BoundsMode.None. I'm using the ParentPercentage to align the different chart areas and that seems to work well. The chart.Width and chart.Depth are set to 40.0 and 28.57 with the slices being set the same for the corresponding dimensions.

I have to think this it is possible to get the size and alignment to work out, but I haven't found the right combination of properties to control. I can post code if needed but there's quite a bit of it and so responding to suggestions or questions may be more efficient.

Thanks in advance for your help.

Regards

Mike Hayford

Attachments
RasterPlus2Slices.jpg (45 views, 52.00 KB)
bob milanov
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi Michael,

No doubt this chart alignment is kind of tricky. Assuming that the charts are called chart1, chart2 and chart3 where chart1 is the surface chart operating in contour mode the alignment code should look like:

            nChartControl1.Panels.Clear();

            nChartControl1.Panels.Add(chart1);
            nChartControl1.Panels.Add(chart2);
            nChartControl1.Panels.Add(chart3);

            NMarginsL margins = new NMarginsL(20, 20, 20, 20);

            chart1.Location = new NPointL(0, 0);
            chart1.Size = new NSizeL(   new NLength(50, NRelativeUnit.ParentPercentage),
                                        new NLength(50, NRelativeUnit.ParentPercentage));

            chart2.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(0));
            chart2.Size = new NSizeL(new NLength(50, NRelativeUnit.ParentPercentage),
                            new NLength(50, NRelativeUnit.ParentPercentage));

            chart3.Location = new NPointL(new NLength(0), new NLength(50, NRelativeUnit.ParentPercentage));
            chart3.Size = new NSizeL(new NLength(50, NRelativeUnit.ParentPercentage),
                            new NLength(50, NRelativeUnit.ParentPercentage));

            chart1.BoundsMode = BoundsMode.Fit;

            float horizontalMarginsInPixels = (margins.Left.Value + margins.Right.Value) * NResolution.ScreenResolution.DpiX / 72;
            float verticalMarginsInPixels = (margins.Top.Value + margins.Bottom.Value) * NResolution.ScreenResolution.DpiY / 72;

            chart1.Width = (nChartControl1.Width * chart1.Size.Width.Value) / 100.0f - horizontalMarginsInPixels;
            chart1.Depth = (nChartControl1.Height * chart1.Size.Height.Value) / 100.0f - verticalMarginsInPixels;
            chart1.Margins = margins;
            chart1.Fit3DAxisContent = false;

            chart2.BoundsMode = BoundsMode.Stretch;
            chart2.MinDockZoneMargins = margins;

            chart3.BoundsMode = BoundsMode.Stretch;
            chart3.MinDockZoneMargins = margins;

There are two points of interest generally:

1. In order to assing widht and depth to the 3D chart, that will make it fit "exactly" in its designated place you should choose width and depth that have the same aspect as the chart panel - this achieved by:

            chart1.BoundsMode = BoundsMode.Fit;

            float horizontalMarginsInPixels = (margins.Left.Value + margins.Right.Value) * NResolution.ScreenResolution.DpiX / 72;
            float verticalMarginsInPixels = (margins.Top.Value + margins.Bottom.Value) * NResolution.ScreenResolution.DpiY / 72;

            chart1.Width = (nChartControl1.Width * chart1.Size.Width.Value) / 100.0f - horizontalMarginsInPixels;
            chart1.Depth = (nChartControl1.Height * chart1.Size.Height.Value) / 100.0f - verticalMarginsInPixels;

2. Notice that I leave margins around the chart panels - this is intentional - the idea is that 2D charts will typically "eat" from the space available for the series plot depending on the size of texts/ticks on their axis - by forcing a 20 points margin and explicitly
locking the size of the axis area:

chart2.MinDockZoneMargins = margins;
chart3.MinDockZoneMargins = margins;

you actually ensure the chart plot size to be panelSize - marginsSize. Note that if the control changes size on the screen you'll have to execute the code again (as the nChartControl1.Width and nChartControl1.Height will change).

Hope this helps - let me know if you meet any problems.

Best regards,
Bob



Michael Hayford
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Bob,

I had to make 2 minor additions to your code:
chart1.Enable3D = True;
chart1.Projection.SetPredefinedProjection(PredefinedProjection.OrthogonalTop);
to get the surface chart to display correctly, but otherwise this approach works great! I've attached the "after" version of the chart I posted before to demonstrate the success with your approach.

I am a little unclear about why the BoundsMode for the 3D chart is set to Fit while the BoundsMode for the 2D charts is Stretch. If there is a simple explanation, I would like to understand it better.

But mainly, I am very happy with your solution! Thank you again for your prompt help.

Regards

Mike

Attachments
RasterPlus2SlicesNew.jpg (41 views, 53.00 KB)


Similar Topics


Reading This Topic