Page 1 of 1

Question about GetAxisLabel

Posted: Mon Nov 06, 2006 6:31 pm
by 9641603
Hi,

I have a plot, I'm using automatic axes. When I don't do anything special, the X axis is neatly divided and I get major ticks at -8, -6, -4, -2 and 0. What I want to do now is to slightly modify these labels - say, replace "0" with "zero". So I'm subscribing to the GetAxisLabel event and making my label change there.

The problem is that as a result my automatic axis is putting the major ticks at different X locations. My guess is that it looks at the lengths of my new labels and rearranges everything. But that's precisely what I don't want!

Any hints on how to modify my labels in GetAxisLabel but without changing the default automatic locations of the major labels?

Posted: Tue Nov 07, 2006 10:33 am
by narcis
Hi Michal,

You can try setting labels separation to zero to make the labels being as close as possible.

Code: Select all

            tChart1.Axes.Bottom.Labels.Separation = 0;
If this is not enough then you may need to use custom labels as you can see in the All Features\Welcome !\Axes\Labels\Custom labels example in the features demo.

Posted: Tue Nov 07, 2006 8:52 pm
by 9641603
Yes, but if I do this, my major ticks will still end up at different locations than where they are created automatically. What I would like is to keep the automatic tick locations but change some of the labels. The problem is that Axis.Labels is empty when I'm setting up my chart. Any solution?

Posted: Wed Nov 08, 2006 12:56 pm
by narcis
Hi Michal,

When using custom labels the ticks are also automatically placed. The features demo example ticks are not spaced equally because labels don't have regular increment. Try using something like this:

Code: Select all

		private void Form1_Load(object sender, EventArgs e)
		{
			tChart1.Aspect.View3D = false;

			Random val = new Random();

			for (int i = -8; i <= 0; i+=2)
			{
				line1.Add(i, val.Next());
			}

			AddCustomLabels();
		}

		private void AddCustomLabels()
		{
			tChart1.Axes.Bottom.Labels.Items.Clear();

			for (int i = 0; i < line1.Count; i++)
			{
				if (line1.XValues[i] == -8) tChart1.Axes.Bottom.Labels.Items.Add(line1.XValues[i], "minus eight");
				if (line1.XValues[i] == -6) tChart1.Axes.Bottom.Labels.Items.Add(line1.XValues[i], "minus six");
				if (line1.XValues[i] == -4) tChart1.Axes.Bottom.Labels.Items.Add(line1.XValues[i], "minus four");
				if (line1.XValues[i] == -2) tChart1.Axes.Bottom.Labels.Items.Add(line1.XValues[i], "minus two");
				if (line1.XValues[i] == 0) tChart1.Axes.Bottom.Labels.Items.Add(line1.XValues[i], "zero");
			}			
		}
Axis.Labels.Items is not empty when using custom labels.