Group: Forum Members
Last Active: 11 Years Ago
Posts: 12,
Visits: 1
|
I am working on a program where I've implemented drag and drop from a ListView control to a docking control that can contain several charts. Part of the functionality in this is to allow users to either create new chart strips, add data to a current chart or put a chart side by side on the same control. I have implemented support for NCartesianCharts and NPolarCharts so far. However, I'm not completely understanding the behavior when I attempt to automatically reposition the charts.
First, when I set the NCartesianCharts.Size property it appears to ignore whichever value is larger (for instance if my chart would be wider than it is tall it makes squared the size of its height). Before this I was able to get the look I wanted by setting the Charts.Dock to DockStyle.Right and BoundsMode to Stretch. However now that I'm manually calculating the size I would have thought I would not need to do that.
Second, when I set the Location of NCartesianChart if the control is squared it appears the position is set correctly. However, again if the scenario is that the control is wider than it is tall it appears to ignore the location I specified.
Third, I'm not sure how NPolarCharts Location is defined. It appears that NCartesianChart places the X,Y based on the lower right of the chart (at the origin). In NPolarChart the behavior I think I'm seeing is that it's Location is based on the center of the chart? I wasn't able to find anything on this online or searching the forums. If that is the case it's fine I will just need to apply an offset depending on the chart type. I have also copied the code I'm using to position my charts. I'm confident that the math is correct but as I said what I'm seeing doesn't match the behavior I'm expecting. Any help at all would be appreciated.
As a final note the scenario is that I have n number of charts of various types that must all fit on the same control. The only things I know is the size of the control, the number of charts to place, and the maximum number of columns I will allow (rows are variable depending on the column). So, I am trying to calculate the size I would need to make the charts give them a buffer on the outside and a smaller buffer between each chart. Then programatically position and size them. Also, I apologize if there is a code format function but I didn't see it so I've just pasted it in as plain text.
private void RepositionCharts() { int lCurrentColumn = 0; int lCurrentRow = 1; int lTotalRows = Charts.Count / mMaxChartColumns;
double lExteriorBuffer = 10.0; double lInteriorBuffer = 1; int lChartCount = Charts.Count; double lChartWidth = (Size.Width - (2 * lExteriorBuffer) - ((mMaxChartColumns - 1) * lInteriorBuffer)) / lChartCount; double lChartHeight = (Size.Height - (2 * lExteriorBuffer) - ((lTotalRows - 1) * lInteriorBuffer)) / lChartCount; float lXLocation; float lYLocation;
NSizeL lChartSize = new NSizeL((float)lChartWidth, (float)lChartHeight);
for (int i = 0; i < Charts.Count; ++i) { for (int j = 0; j < lTotalRows; ++j) { Charts[i].Size = lChartSize;
lXLocation = (float)((lCurrentColumn * lChartWidth) + lInteriorBuffer + lExteriorBuffer); lYLocation = (float)((j * lChartHeight) + lInteriorBuffer + lExteriorBuffer); Charts[i].Location = new NPointL(lXLocation, lYLocation);
if (++lCurrentColumn >= mMaxChartColumns) { lCurrentColumn = 0; ++lCurrentRow; } } } }
|