Page 1 of 1

Setting axis maximum doesn't work in BeforeDrawAxes event (only in BeforeDraw event)

Posted: Wed Jan 30, 2019 6:03 am
by 15685014
Hello.
I'm using TeeChart Pro 4.2018.12.17 and I use the following code:

Code: Select all

using System;
using System.Windows.Forms;
using Steema.TeeChart;

namespace TeeChartTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            tChart1.Axes.Left.Automatic = false;
            tChart1.Axes.Left.Minimum = 0;
            tChart1.Axes.Left.Maximum = 5;

            //adding points which are higher than tChart1.Axes.Left.Maximum
            fastLine1.Add(0, 7);
            fastLine1.Add(1, 7);
        }


        private void tChart1_BeforeDrawAxes(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            //adjust tChart1.Axes.Left.Maximum if there are points that are higher
            if (fastLine1[0].Y > tChart1.Axes.Left.Maximum)
                tChart1.Axes.Left.Maximum = fastLine1[0].Y;
        }
    }
}
Setting tChart1.Axes.Left.Maximum inside BeforeDrawAxes event doesnt' work (axis will have proper maximum value only if I force TeeChart to redraw immediately - tChart1.Refresh();).
Or I can use BeforeDraw event (and it works correctly without forcing to redraw).
Is that by design or a bug?
BeforeDrawAxes event is supposed to be for all axis manipulations, isn't it?

Re: Setting axis maximum doesn't work in BeforeDrawAxes event (only in BeforeDraw event)

Posted: Wed Jan 30, 2019 12:57 pm
by Christopher
Hello!
bairog wrote:
Wed Jan 30, 2019 6:03 am
BeforeDrawAxes event is supposed to be for all axis manipulations, isn't it?
not exactly - it's primary function is for drawing custom elements onto the chart at different stages of the chart's drawing routines, as can be seen in the demo here:
TeeChartNetExamples_2019-01-30_13-49-28.png
TeeChartNetExamples_2019-01-30_13-49-28.png (190.95 KiB) Viewed 8811 times
given that the chart calculates the position of it's elements at the time of drawing, this means that axes properties set in the BeforeDrawAxis event may be overwritten as the chart makes its calculations at the time of drawing the axes (and not before it).