Dynamically showing/hiding axis labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Michal Blazejczyk
Newbie
Newbie
Posts: 64
Joined: Fri Jun 16, 2006 12:00 am

Dynamically showing/hiding axis labels

Post by Michal Blazejczyk » Fri Nov 20, 2009 9:31 pm

Hello,

I have a plot where I need to display or hide the labels of the left axis depending on whether the plot height (in pixels) is big enough.

I've tried setting it up during the original plot setup but the size of the plot area is not known at that point.

I've also tried to use BeforeDrawAxes and BeforeDrawSeries events - the problem is that setting Axis.Labels.Visible in the event handlers doesn't update the axis properly.

Best,
Michal
Best,
Michal Blazejczyk
Lead Programmer
Genome Quebec

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Sandra » Mon Nov 23, 2009 10:08 am

Hello Michal Blazejczyk,
I've tried setting it up during the original plot setup but the size of the plot area is not known at that point.

I've also tried to use BeforeDrawAxes and BeforeDrawSeries events - the problem is that setting Axis.Labels.Visible in the event handlers doesn't update the axis properly.
I think that you need to paint axes before calculate either value, so you can get values of you want. Please check if using tChart1.Draw(), tChart1.refresh, tChart1.Invalidate() or Bitmap bitmap1= tChart1.Bitmap, your application works fine. If it doesn't the problem, please you could send us a simple example, because we can reproduce issue here.


I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Michal Blazejczyk
Newbie
Newbie
Posts: 64
Joined: Fri Jun 16, 2006 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Michal Blazejczyk » Mon Nov 23, 2009 10:34 pm

Hi Sandra,

I started to create a test project, but in fact, I think it will be easier if we turned this question around.

Could you create a small project for me with a single data series (say, of type Points). And I would like that if the plot area (but NOT the entire chart window - only the area between axes) becomes less high than 50 pixels, the labels on the Y axis disappear.

Could you try and do it for me?

Best,
Michal
Best,
Michal Blazejczyk
Lead Programmer
Genome Quebec

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Sandra » Tue Nov 24, 2009 11:09 am

Hello Michal,

I couldn't reproduce your problem using last version of TeeChart . Net and next code:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Points points1;
        private void InitializeChart()
        {
            tChart1.Dock = DockStyle.Fill;
            points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points1.FillSampleValues(10);
            tChart1.Draw();
        }
Please, check that previous code works fine in your application resizing chart to obtain an image as next:
Chart2.JPG
Chart2.JPG (13.11 KiB) Viewed 14613 times
Although this image is very small, labels appear. Specifically in this case only a label appears that is marked with a red rectangle, but it doesn't disappear. If your code doesn’t work correctly, please you could say what version of TeeChart .Net are you using?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Michal Blazejczyk
Newbie
Newbie
Posts: 64
Joined: Fri Jun 16, 2006 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Michal Blazejczyk » Tue Nov 24, 2009 4:40 pm

Hi Sandra,

I'm afraid you are misunderstanding me. This post is not related to my other post ("Detecting too small plot area?").

The issue raised in this post is the following: I would like that Y axis labels disappear completely once the plot area becomes smaller than, say, 50 pixels in height.
I need to write custom code to handle this case. I have tried a few approaches, but the axis don't refresh properly.

So, in the example you have given, I would like the "0" label (or any other labels) on the Y axis not to be there at all if the plot area is small. But when the plot area gets bigger, I would like the labels to appear again.

I was hoping you could show me how I can implement this.

Best,
Michal
Best,
Michal Blazejczyk
Lead Programmer
Genome Quebec

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Sandra » Wed Nov 25, 2009 9:56 am

Hello Michal,

Thanks, for your information. I made a simple project that I think you could use for your application, see next code:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Points points1;
        private void InitializeChart()
        {
            tChart1.Dock = DockStyle.Fill;
            tChart1.Aspect.View3D = false;
            points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points1.FillSampleValues(10);
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
            tChart1.Draw();
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            Rectangle rect = new Rectangle();
            rect = tChart1.Chart.ChartRect;
         
            if (rect.Height <=50)
            {
                tChart1.Axes.Left.Labels.Visible = false;
            }
            else
            {
                tChart1.Axes.Left.Labels.Visible = true;
            }
         
        } 
As you can see in previous code, you need AfterDraw Event, and tChart1.Draw() property, because chart is updated, and labels appears and disappears.

I hope will helps.


Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Michal Blazejczyk
Newbie
Newbie
Posts: 64
Joined: Fri Jun 16, 2006 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Michal Blazejczyk » Wed Nov 25, 2009 8:44 pm

Hi Sandra,

I think the problem is that I'm using Axis.Labels.Items to provide custom axis labels.

Code: Select all

        private void InitializeChart()
        {
            Points points = new Steema.TeeChart.Styles.Points( _chart.Chart );
            points.Add( new int[] { 1, 5, 10, 15, 20 }, new int[] { 1, 5, 10, 15, 20 } );

            ArrayList rowNames = new ArrayList( 20 );
            for( int i = 1; i <= 20; i++ )
            {
                rowNames.Add( "Row " + i.ToString() );
            }

            Steema.TeeChart.AxisLabelsItems rowLabels = _chart.Axes.Left.Labels.Items;
            rowLabels.Clear();
            for( int i = 0; i < rowNames.Count; ++i )
            {
                rowLabels.Add( i, rowNames[ i ].ToString() );
            }
        }
In my version of TeeChart, when the plot area gets too small, the axis labels are simply drawn to the right of the axis.

Best,
Michal
Best,
Michal Blazejczyk
Lead Programmer
Genome Quebec

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Sandra » Thu Nov 26, 2009 11:36 am

Hello Michal,

I couldn't reproduce your problem here using your code. I made a modifile in last code I sent you:

Code: Select all

       
        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Points points;
        private System.Collections.ArrayList rowNames;
        private void InitializeChart()
        {
            tChart1.Dock = DockStyle.Fill;
            points = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points.Add(new int[] { 1, 5, 10, 15, 20 }, new int[] { 1, 5, 10, 15, 20 });
            rowNames = new System.Collections.ArrayList(20);
            AddCustomLabels();
            tChart1.Resize += new EventHandler(tChart1_Resize);
            tChart1.Draw();
        }
        private void AddCustomLabels()
        {
            for (int i = 1; i <= 20; i++)
            {
                rowNames.Add("Row " + i.ToString());
            }
            Steema.TeeChart.AxisLabelsItems rowLabels = tChart1.Axes.Left.Labels.Items;
            rowLabels.Clear();
            for (int i = 0; i < rowNames.Count; ++i)
            {
                rowLabels.Add(i, rowNames[i].ToString());
            }


        }
        void tChart1_Resize(object sender, EventArgs e)
        {
            tChart1.Draw();
            Rectangle rect = new Rectangle();
            rect = tChart1.Chart.ChartRect;
            if (rect.Height <= 50)
            {
                Steema.TeeChart.AxisLabelsItems rowLabels = tChart1.Axes.Left.Labels.Items;
                rowLabels.Clear();
                tChart1.Axes.Left.Labels.Visible = false;
            }
            else
            {
                tChart1.Axes.Left.Labels.Visible = true;
                AddCustomLabels();
            }
         
        }

Please check previous code works fine in your application. If this not works fine, please you could say what version is of are you using at the moment?


Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Michal Blazejczyk
Newbie
Newbie
Posts: 64
Joined: Fri Jun 16, 2006 12:00 am

Re: Dynamically showing/hiding axis labels

Post by Michal Blazejczyk » Thu Nov 26, 2009 10:57 pm

Hi Sandra,

Thank you, it works well inside the Resize() event and with removing of all labels prior to hiding them.

Best,
Michal
Best,
Michal Blazejczyk
Lead Programmer
Genome Quebec

Post Reply