Page 1 of 1
Disabling Axis labels also disables grid
Posted: Fri Jun 15, 2012 9:11 am
by 16061923
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 ???
Re: Disabling Axis labels also disables grid
Posted: Fri Jun 15, 2012 12:34 pm
by narcis
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.
Re: Disabling Axis labels also disables grid
Posted: Fri Jun 15, 2012 2:28 pm
by 16061923
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)?
Re: Disabling Axis labels also disables grid
Posted: Fri Jun 15, 2012 3:21 pm
by 10050769
Hello NDoKi,
Can you tell us which version of TeeChartFor.Net are you using?
Thanks,
Re: Disabling Axis labels also disables grid
Posted: Fri Jun 15, 2012 3:31 pm
by 16061923
I'm currently using the latest version: 4.1.2012.5103.
Re: Disabling Axis labels also disables grid
Posted: Mon Jun 18, 2012 8:30 am
by 10050769
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 (78 KiB) Viewed 12719 times
Thanks,
Re: Disabling Axis labels also disables grid
Posted: Mon Jun 18, 2012 9:30 am
by 16061923
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.
Re: Disabling Axis labels also disables grid
Posted: Mon Jun 18, 2012 1:58 pm
by 10050769
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,
Re: Disabling Axis labels also disables grid
Posted: Mon Jun 18, 2012 3:55 pm
by 16061923
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.
Re: Disabling Axis labels also disables grid
Posted: Tue Jun 19, 2012 9:35 am
by 10050769
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,
Re: Disabling Axis labels also disables grid
Posted: Tue Jun 19, 2012 11:12 am
by 16061923
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!
Re: Disabling Axis labels also disables grid
Posted: Tue Jun 19, 2012 2:55 pm
by 10050769
Hello NDoki,
I am glad finally, we can find a good solution for you.
Thanks,