Page 1 of 1

custom y axes title

Posted: Mon Mar 03, 2025 9:10 am
by 21099317
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?

Re: custom y axes title

Posted: Mon Mar 03, 2025 10:37 am
by edu
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 293 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

Re: custom y axes title

Posted: Mon Mar 03, 2025 11:13 am
by 21099317
and what if the relative positions are negative and the position units is by pixels?

Re: custom y axes title

Posted: Mon Mar 03, 2025 1:51 pm
by edu
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