custom y axes title

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
TomAgos
Newbie
Newbie
Posts: 11
Joined: Thu Jan 16, 2025 12:00 am

custom y axes title

Post by TomAgos » Mon Mar 03, 2025 9:10 am

Hey
im creating a few custom y axes and im placing them like this:
Image

(if the image isnt working, the y axes is on the left of the chart)
i need to add titles or some text for every axis, but i want the title to be on top of the axis, what is the simplest way to do that?

Edu
Newbie
Newbie
Posts: 46
Joined: Tue Nov 28, 2023 12:00 am

Re: custom y axes title

Post by Edu » Mon Mar 03, 2025 10:37 am

Hello,

A way to achieve this is through the AfterDraw event ( _TChart.AfterDraw += _TChart_AfterDraw; )

I set up an example for you:

Code: Select all

        private void _TChart_AfterDraw(object sender, IGraphics3D g)
        {
            // Keep in mind what PositionUnits we're using. I'm choosing Percent, adjust accordingly.
            _YAxis.PositionUnits = PositionUnits.Percent;
            axis1.PositionUnits = PositionUnits.Percent;


            // I prefer storing the text inside the Title property, but make it invisible = false.
            axis1.Title.Visible = false;
            axis1.Title.Text = "Middle";
            _YAxis.Title.Visible = false;
            _YAxis.Title.Text = "Left";


            // Add to a List if we want to use a foreach loop, definitely not needed
            List<Axis> axes = new List<Axis>();
            axes.Add(_YAxis);
            axes.Add(axis1);

            foreach(Axis axis in axes)
            {
                double xPosPercent = axis.RelativePosition;
                double distance;

                if (xPosPercent == 0)
                {
                    // Axis is at the very left of the chart. 30 is just an example that works for this demo.
                    distance = 30;
                }
                else
                {
                    distance = _TChart.Width * (xPosPercent / 100);
                }

                //Finally, place the text with  g.TextOut, which offers different overloads if desired
                g.TextOut((int)distance, 0, axis.Title.Text);
            }

        }
And this is how it would look like:
AxisTitle1.png
AxisTitle1.png (25.75 KiB) Viewed 182 times
You can find more information in our docs: https://www.steema.com/docs/TeeChartNETTutorials.htm (Tutorial 4, "Axis Control")

If this approach doesn't work for you or if you need anything else, let me know!

Best regards,
Edu
Edu
Steema Support

TomAgos
Newbie
Newbie
Posts: 11
Joined: Thu Jan 16, 2025 12:00 am

Re: custom y axes title

Post by TomAgos » Mon Mar 03, 2025 11:13 am

and what if the relative positions are negative and the position units is by pixels?

Edu
Newbie
Newbie
Posts: 46
Joined: Tue Nov 28, 2023 12:00 am

Re: custom y axes title

Post by Edu » Mon Mar 03, 2025 1:51 pm

Hello,

A negative relative position and pixel-based positioning shouldn't cause issues when determining the axis position and using g.TextOut(x, y, text).

If you're experiencing difficulties, could you share a sample of your code, including the chart's width, axis position, etc.? That way, I can replicate your setup and provide a more specific example.

Best regards,
Edu
Edu
Steema Support

Post Reply