Disabling Axis labels also disables grid

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
NDoki
Newbie
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 12:00 am

Disabling Axis labels also disables grid

Post by NDoki » Fri Jun 15, 2012 9:11 am

I need to disable axis labels to be able to align better with some other controls in my application. Problem is disabling these labels also disables the gridlines. That's not what I want, I need the gridlines.

Things i tried and not working:

Axes.Bottom.Labels.Style = AxisLabelStyle.None; // hides gridlines
Axes.Bottom.Labels.Visible = false; // also hides gridlines
Axes.Bottom.Labels.Color = Colors.Transparent; // transparent labels do not work
Axes.Bottom.Labels.Pen.Color = Colors.Transparent; // transparent labels do not work
Axes.Bottom.Labels.Pen.Visible = false; // disabling labelpen does not work
Axes.Bottom.Labels.Gradient.Visible = false; // disabling labelpen does not work
Axes.Bottom.Labels.Height = 0; // setting height does not work

Any solutions that can help ???

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Disabling Axis labels also disables grid

Post by Narcís » Fri Jun 15, 2012 12:34 pm

Hi NDoki,

You can set labels to an blank space string using GetAxisLabel event, for example:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }
    
    private void InitializeChart()
    {
      tChart1.Series.Add(new Steema.TeeChart.Styles.Points()).FillSampleValues();
      tChart1.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(tChart1_GetAxisLabel);
    }

    void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
    {
      if (sender.Equals(tChart1.Axes.Left))
      {
        e.LabelText = " ";
      }
    }
BTW, you can also align charts as Yeray explained here.
Best Regards,
Narcís Calvet / 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

NDoki
Newbie
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 12:00 am

Re: Disabling Axis labels also disables grid

Post by NDoki » Fri Jun 15, 2012 2:28 pm

I tried your solution but this also removes gridlines from the vertical axis. Why are they connected to each other if they can be separately disabled (visible is false)?

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

Re: Disabling Axis labels also disables grid

Post by Sandra » Fri Jun 15, 2012 3:21 pm

Hello NDoKi,

Can you tell us which version of TeeChartFor.Net are you using?

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

NDoki
Newbie
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 12:00 am

Re: Disabling Axis labels also disables grid

Post by NDoki » Fri Jun 15, 2012 3:31 pm

I'm currently using the latest version: 4.1.2012.5103.

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

Re: Disabling Axis labels also disables grid

Post by Sandra » Mon Jun 18, 2012 8:30 am

Hello NDoki,

Ok. Can you attached a image where appears your problem because we can try to find a solution for you? So, using the code Narcís has suggested you, I don't see your problem here and I get next results that I consider correct:
SurfaExample.jpg
SurfaExample.jpg (78 KiB) Viewed 12731 times

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

NDoki
Newbie
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 12:00 am

Re: Disabling Axis labels also disables grid

Post by NDoki » Mon Jun 18, 2012 9:30 am

I did made a mistake. I supplied string.empty instead of a space. This leaves the gridlines enabled but does consume the space needed for the labels. This space is too big for me. I need to be able to create a 2-3 pixels margin.

I created an example to show the problem dl at: https://www.dropbox.com/s/td5gig5hbaair ... Labels.zip

- What i need is result of using method SetBottomAxisCaseOne but this disables gridlines.
- I also created SetBottomAxisCaseTwo. With that case you should also try supllying string.empty.

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

Re: Disabling Axis labels also disables grid

Post by Sandra » Mon Jun 18, 2012 1:58 pm

Hello NDoki,
- What i need is result of using method SetBottomAxisCaseOne but this disables gridlines.
The method SetBottomAxisCaseOne disabled the grid line becuse the labels don't have any values to show and is necessary to draw Grid that the labels have some value.
- I also created SetBottomAxisCaseTwo. With that case you should also try supllying string.empty.
I think you can set visible ticks and minor ticks to false to achieve the same result as you use SetBottomAxisCaseOne without GridLines disappear:

Code: Select all

   public MainWindow()
        {
            InitializeComponent();
            ChartControl.Chart = new Steema.TeeChart.WPF.Chart();
            ChartControl.Chart.Aspect.View3D = false;
            ChartControl.Legend.Visible = false;
            ChartControl.Axes.Bottom.Ticks.Visible = false;
            ChartControl.Axes.Bottom.MinorTicks.Visible = false;
            Line line = new Line();
            line.FillSampleValues(20);
            ChartControl.Series.Add(line);
            ChartControl.Panel.MarginUnits = Steema.TeeChart.WPF.PanelMarginUnits.Pixels;
            ChartControl.Panel.MarginBottom = -10;
            ChartControl.Panel.MarginLeft = -10;
            // Case 2: Solution overriding axislabelevent
            SetBottomAxisCaseTwo();
        }
        private void SetBottomAxisCaseOne()
        {
            ChartControl.Axes.Bottom.Labels.Visible = false;// <-- this disables gridlines which it shouldn't
        }

        private void SetBottomAxisCaseTwo()
        {
            ChartControl.GetAxisLabel += new Steema.TeeChart.WPF.GetAxisLabelEventHandler(ChartControl_GetAxisLabel);
        }

        void  ChartControl_GetAxisLabel(object sender, Steema.TeeChart.WPF.GetAxisLabelEventArgs e)
        {
 	        if (sender.Equals(ChartControl.Axes.Left) ||  sender.Equals(ChartControl.Axes.Bottom))
            {
                e.LabelText = " ";
                // Also try suplying string.empty --> e.LabelText = string.Empty;
                (sender as Steema.TeeChart.WPF.Axis).Ticks.Visible = false;
                (sender as Steema.TeeChart.WPF.Axis).MinorTicks.Visible = false;
               
            }          
        }
Can you tell us if previous code works as you expect?

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

NDoki
Newbie
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 12:00 am

Re: Disabling Axis labels also disables grid

Post by NDoki » Mon Jun 18, 2012 3:55 pm

Hi Sandra,

Your solution works for me. But it still looks like some kind of 'hack'. I think I should be able to draw no labels if I want the chart to do that.

Another solution should do the same but also is not working is: Axes.Bottom.Labels.Style = AxisLabelStyle.None;

As the name is telling me I don't want labels to show up, but this does not tell me labels are linked to the gridlines and will also disappear.

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

Re: Disabling Axis labels also disables grid

Post by Sandra » Tue Jun 19, 2012 9:35 am

Hello NDoki,


Ok, I have debugged source code and I have good news for you. Basically, I have seen that the property TickOnLabelsOnly of Axes, is set to true by default. Therefore, if you disable the labels you need set to false the property TickOnLabelsOnly as do in next line of code:

Code: Select all

ChartControl.Axes.Bottom.TickOnLabelsOnly = false;
Can you tell us if my suggestion help you to achieve as you want?

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

NDoki
Newbie
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 12:00 am

Re: Disabling Axis labels also disables grid

Post by NDoki » Tue Jun 19, 2012 11:12 am

Yes! You made my day. This works for me:

Code: Select all

ChartControl.Axes.Bottom.TickOnLabelsOnly = false;
ChartControl.Axes.Bottom.Labels.Visible = false;
ChartControl.Axes.Bottom.Ticks.Visible = false;
ChartControl.Axes.Bottom.MinorTicks.Visible = false;
Thank you Sandra!

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

Re: Disabling Axis labels also disables grid

Post by Sandra » Tue Jun 19, 2012 2:55 pm

Hello NDoki,

I am glad finally, we can find a good solution for you.

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

Post Reply