Microsoft WinForms Chart Control - Set Position of Y-Axis Label - c#

I have a Y-Axis Label as shown here:
I am trying to position the label closer to the chart, is there any facility to do this?
I could add a Winforms Label and position it accordingly but just in case there is a better way.

If you are talking about the AxisY.Title AvGkW you can't position it other than aligning it near, center, far.
But you can add as many Titles to your Chart as you want, dock them to all four corners of the earth, um, Chart, style them and set their offset..
After you have added your Title like this:
Title TT = new Title( yourTitleText, Docking.Left, yourFont, yourcolor);
TT.Docking = Docking.Left;
yourChart.Titles.Add(TT);
You can move it left and right like this:
TT.DockingOffset = yourOffset;
It isn't in the specs here on MSDN but as usual it is in 1/100 of the Chart.Size, so setting it to 50 moves the Title into the middle of the ChartArea.. It is an int32 strangely!
You will have to play with the number depending on the size of the Y-Labels and the position of the Y-Axis. Values of 2-7 are OK here..

Related

add space between .net chart and lable

How can I move the labes down?
I would like to add some space between the chart and the labels. It is possible?
I'm using System.Web.UI.DataVisualization.Charting.Chart
Like in this edited in mspaint:
This answer will be under the assumption that you are using CustomLabels on the X-axis:
It is possible, but I am not aware of such a setting. But I can offer a pragmatic solution (i.e. a bit of a hack): Namely you reenable the gridtickmarks on the X-axis, but set Color to Transparent, after that you can adjust the distance to the axis by using MajorTickMark.Size (default 1), the tick marks will not be visible:
chart.ChartAreas[0].AxisX.MajorTickMark.Enabled = true;
chart.ChartAreas[0].AxisX.MajorTickMark.LineColor = Color.Transparent;
chart.ChartAreas[0].AxisX.MajorTickMark.Size = 1;
// You can increase MajorTickMark.Size to increase distance to the axis
And incase someone want to have both visible tickmarks and labels on an axis:
Look into using DataPoint.AxisLabel in your series rather than using CustomLabels on the X-axis. DataPoint.AxisLabel will add a label on the axis for each datapoint. The axis-labels will then have the same distance to the axis as normal interval labels. There is a trick to it, that if the first and last data point in a series have an AxisLabel set the axis interval numbers will be hidden and leave only the axis labels.

Write vertical text using Direct2D's DirectWrite

I want to write vertical text like it is known from a simple chart's y-axis. I found the FlowDirection property which allows me to add the "ToptoBottom" direction but this does not change the text's behaviour.
Is it the only way to rotate the rendertarget by 90 degress, write the text and rotate it back? The problem here is that I also have to recalculate the points for the rotation matrix.
This seems a lot of work just for rotating text? Any better idea?
Im not in front of my computer right now so bear with me. When you are creating the text format you can set the width of the bounding box of the text to the text font size and it should only write one letter per line, giving you vertical text effect that you want!

C# Y coordinate is always offset

I'm a bit stuck with this one.
I'm writing a visual Semaphore flag signalling application, and I'm having a bit of trouble with the positioning of labels for left and right arms.
This is the code before:
private void leftHandDown()
{
display.DrawLine(penLeftArm, centXCoord, centYCoord, LHDownXCoord, LHDownYCoord);
lblLeftHand.Top = LHDownYCoord;
lblLeftHand.Left = LHDownXCoord;
lblLeftHand.Show();
}
And this is what it looks like:
http://i137.photobucket.com/albums/q221/omar319/sema.png (I don't have any rep to post photos on here). I have set the background to blue, as I'm also trying to pin down another problem (labels leave a white box when they change position, not sure why).
I would like the labels to appear at the end of the hands drawn by the pen (end coordinates LHDownXCoord and LHDownYCoord) but the labels are always offset by -80px on the y-axis. The Right Hand label I have added 75px to the Y axis coordinate.
Any idea what is causing the offset?
Cheers,
Omar
I think the labels need to be offset by the top left coordinates of your display control

Show gridline in chart

I have a c# chart control that shows dates along the horizontal (x) axis. I want to show gridlines only on thosex axis points that represent the start of the month. How may I do this.
I guess you mean mscharts so it could be
chartArea.AxisX.MinorGrid.Enabled = false;
The ones corresponding to the datapoints is the MajorGrid which can also be toggled similarly.
you can also do the same for the Y axis too.

How can I programmatically determine the width of Y-axis section of a WPF chart?

I am developing a WPF application that has a stacked column chart (I'm using the Silverlight Toolkit charting features). I need to dynamically overlay a semi-transparent rectangle over a section of the chart - the size and location of the rectangle needs to adapt to the number of data points on the X axis. The X-axis values represent days, the number of which may vary, but the rectangle always needs to cover 30 days.
In any case, I've figured out most of it, but I need to find out how much width the Y-axis label section of the chart is taking up so that I can take it into account in my rectangle size and location calculations.
There is an "Actual Width" property for the chart available, but I don't know how to get the actual width for just the Y-axis label area. Does anyone know how to find this?
I was able to address this issue by waiting until the chart was loaded and then using the techniques described here http://www.scottlogic.co.uk/blog/colin/2009/03/adding-a-location-crosshair-to-silverlight-charts-again/.
The key thing here is to do the processing when the Loaded event is received:
MyChart.Loaded += (sender, e) =>
{
// MyChart is about to be rendered
// it's now safe to access the ActualWidth properties of the chart components
MyRectangle.Left = MyChart.ActualWidth/2;
}

Categories

Resources