What I am trying to accomplish controling the margins to the left and right of the graph such that when I have added custom axes all information for each axis that has data plotted to it remains visible.
Here is my situation. I have a graph that can have up to 6 Y Axes displayed (3 left side and 3 right side). 4 of these obviously are custom axes.
Any combination of the vertical axes should be able to be shown depending on if the user has assigned any series to those axes. For example, the inner-most left and right can be visible (these are the Left and Right provided by the chart itself) or you have have only the outter-most Y on each side visible (these are custom axes).
What I am having to do is set a margin amount so that all axes that are supposed to be visible can be completely seen (including labels and title).
I am using the Panel.LeftMargin and Panel.RightMargin items to set this value but I seem to get different reactions for the same numbers when the Left and Right axes (not my custom ones but the standard ones) are not being displayed. I have set the Panel.MarginUnits to Pixels and have also tried usingPercent but it appears that assiging the same value (97 pixels in one example) to the LeftMargin gives me a different spacing on the left side depending on whether or not the Axes.Left axis is visible or not.
Maybe I am using the wrong set of properties to control this padding between the edge of the control and the edge of the displayed axes.
Is there any info you can give me on how these properties are supposed to work or another way to control this spacing?
A little help with Margin settings on my chart please
-
- Newbie
- Posts: 38
- Joined: Thu Feb 01, 2007 12:00 am
-
- Newbie
- Posts: 38
- Joined: Thu Feb 01, 2007 12:00 am
Ok, I think I have figured out what I needed to do with the edge margins when displaying multiple custom axes.
Now what I am looking for is how to set the Axes.Left.Labels.CustomSize value based on the longest string that will appear as a label on the Left axis.
I can figure out what the length of the longest string is, but no matter where I try to put the line that will adjust the size of the CustomSize property, it does not appear to make it into the current draw.
I have tried setting the Axes.Left.Labels.CustomSize in BeforeDrawAxes, BeforeDraw, AfterDraw on the chart component itself and none of those seem to get the setting in prior to the draw of the labels.
Here is what I am using:
int maxLength = Math.Max(this.MYChart.Axes.Left.Minimum.ToString(this.MyChart.Axes.Left.Labels.ValueFormat).Length, this.MyChart.Axes.Left.Maximum.ToString(this.MYChart.Axes.Left.Labels.ValueFormat).Length);
this.MYChart.Axes.Left.Labels.CustomSize = maxLength * characterSize;
I am finding the maximum string length by the longest string between the min and max values on the axis. The min and max are properly set at the time I am evaluating this code and the CustomSize property appears to get set correctly but the labels draw without this increased spacing between them and the axis title.
If I redraw the plot again, the spacing gets set correctly.
I am not sure what this might be happening unless I am trying to set this CustomSize property too late in the process to get picked up and used on the axis.
Any idea?
Now what I am looking for is how to set the Axes.Left.Labels.CustomSize value based on the longest string that will appear as a label on the Left axis.
I can figure out what the length of the longest string is, but no matter where I try to put the line that will adjust the size of the CustomSize property, it does not appear to make it into the current draw.
I have tried setting the Axes.Left.Labels.CustomSize in BeforeDrawAxes, BeforeDraw, AfterDraw on the chart component itself and none of those seem to get the setting in prior to the draw of the labels.
Here is what I am using:
int maxLength = Math.Max(this.MYChart.Axes.Left.Minimum.ToString(this.MyChart.Axes.Left.Labels.ValueFormat).Length, this.MyChart.Axes.Left.Maximum.ToString(this.MYChart.Axes.Left.Labels.ValueFormat).Length);
this.MYChart.Axes.Left.Labels.CustomSize = maxLength * characterSize;
I am finding the maximum string length by the longest string between the min and max values on the axis. The min and max are properly set at the time I am evaluating this code and the CustomSize property appears to get set correctly but the labels draw without this increased spacing between them and the axis title.
If I redraw the plot again, the spacing gets set correctly.
I am not sure what this might be happening unless I am trying to set this CustomSize property too late in the process to get picked up and used on the axis.
Any idea?
Hi Aaron
There is a property to find the maximum string length, MaxLabelsWidth() property, you can change your lines code by this:
The "BeforeDrawAxes" event is the first that have got the definitive value, so you should to use it.
Also you have to repaint the Chart after the initialization, in the "FormLoad". This is necessary for the new CustomSize, will be drawn correctly. You can do this as below code:
Attention, where you put the Bitmap, can do a infinite loop. For example, if you will put in the BeforeDrawAxes event.
There is a property to find the maximum string length, MaxLabelsWidth() property, you can change your lines code by this:
Code: Select all
tChart1.Axes.Left.Labels.CustomSize = tChart1.Axes.Left.MaxLabelsWidth();
Also you have to repaint the Chart after the initialization, in the "FormLoad". This is necessary for the new CustomSize, will be drawn correctly. You can do this as below code:
Code: Select all
Bitmap bmp = tChart1.Bitmap;
-
- Newbie
- Posts: 38
- Joined: Thu Feb 01, 2007 12:00 am
Seems to me that what you are saying is that in order to properly set this spacing and have it drawn, I need to have this chart drawn twice?Also you have to repaint the Chart after the initialization, in the "FormLoad". This is necessary for the new CustomSize, will be drawn correctly. You can do this as below code:
Code:
Bitmap bmp = tChart1.Bitmap;
Attention, where you put the Bitmap, can do a infinite loop. For example, if you will put in the BeforeDrawAxes event.
If I set the spacing in the BeforeDrawAxes event, I then need to redraw to get that setting to take affect. Which means an additional draw.
This isn't a huge issue if you are only dealing with 2000 points on your plot but we regularly have plots with upwards of 3-5 MILLION points on them. Those do not draw fast and I do not want to have to draw them twice each time.
Why is it that within the BeforeDrawAxes, setting the spacing values does NOT actually get picked up by the current draw? It seems to me that if you are BEFORE the draw of the axis I would expect these values to be used in the current draw.
Any possibility that this can be changed? The 2nd draw idea is just not going to work for us.
Hello,
The Chart works on the basis of fitting based on the calculation of the Margin with respect to principle Axes and their elements (Labels, Ticks, Axis Pen). It does not do so for Custom Axes as they were conceived as 'custom' to expressly permit the custom definition of contents.
A couple of options I see here, I've tested both and they appear to work fine, are:
- Use only Custom Axes, associating your Series with them, and set all default Axes (Left, Top, Right, Bottom) to Visible False. Switch in and out the Custom Axes as you please with the Margin set, fixed as you require.
or...
- Hide Default Axes' 'Paint' elements only (as opposed to setting Axis Visible False). The Margin location will then not recalculate as the contents still exist but are transparent. This should only be done for the principle Axes if used (Left, Top, Right, Bottom). Example here with Left Axis:
With either option you should see no lateral movement of the Chart as you switch in the Axes.
Regards,
Marc Meumann
The Chart works on the basis of fitting based on the calculation of the Margin with respect to principle Axes and their elements (Labels, Ticks, Axis Pen). It does not do so for Custom Axes as they were conceived as 'custom' to expressly permit the custom definition of contents.
A couple of options I see here, I've tested both and they appear to work fine, are:
- Use only Custom Axes, associating your Series with them, and set all default Axes (Left, Top, Right, Bottom) to Visible False. Switch in and out the Custom Axes as you please with the Margin set, fixed as you require.
or...
- Hide Default Axes' 'Paint' elements only (as opposed to setting Axis Visible False). The Margin location will then not recalculate as the contents still exist but are transparent. This should only be done for the principle Axes if used (Left, Top, Right, Bottom). Example here with Left Axis:
Code: Select all
bool axesLeftVisible = true;
private void button1_Click(object sender, EventArgs e)
{
axesLeftVisible = !axesLeftVisible;
if (!axesLeftVisible)
{
tChart1.Axes.Left.AxisPen.Transparency = 100;
tChart1.Axes.Left.Labels.Font.Brush.Transparency = 100;
tChart1.Axes.Left.Ticks.Transparency = 100;
tChart1.Axes.Left.MinorTicks.Transparency = 100;
}
else
{
tChart1.Axes.Left.AxisPen.Transparency = 0;
tChart1.Axes.Left.Labels.Font.Brush.Transparency = 0;
tChart1.Axes.Left.Ticks.Transparency = 0;
tChart1.Axes.Left.MinorTicks.Transparency = 0;
}
}
Regards,
Marc Meumann
Steema Support