We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I hide the PrimaryYaxis and show only the custom axis?

 

To display only the custom axis, please do the following steps.

1. You have to set the LayoutMode of both X and Y axis to stacking mode.

C#

chartControl1.ChartArea.XAxesLayoutMode = ChartAxesLayoutMode.Stacking;

chartControl1.ChartArea.YAxesLayoutMode = ChartAxesLayoutMode.Stacking;

VB

chartControl1.ChartArea.XAxesLayoutMode = ChartAxesLayoutMode.Stacking

chartControl1.ChartArea.YAxesLayoutMode = ChartAxesLayoutMode.Stacking

2. You have to position the custom Y axis in LayoutCompleted event. Please refer to the following code snippet.

C#

this.chartControl1.LayoutCompleted += new EventHandler(chartControl1_LayoutCompleted);

void chartControl1_LayoutCompleted(object sender, EventArgs e)

{

PositionAllYAxes();

}

ChartAxis a;

private void PositionAllYAxes()

{

for (int i = 0; i < chartControl1.Axes.Count; i++)

{

a = chartControl1.Axes[i];

if (a != chartControl1.PrimaryYAxis && a.Orientation == ChartOrientation.Vertical)

{

a.LocationType = ChartAxisLocationType.Set;

a.Location = new PointF(chartControl1.PrimaryYAxis.Location.X, chartControl1.PrimaryYAxis.Location.Y);

}

}

}

VB

AddHandler chartControl1.LayoutCompleted, AddressOf chartControl1_LayoutCompleted

Private a As ChartAxis

Private Sub chartControl1_LayoutCompleted(ByVal sender As Object, ByVal e As EventArgs)

PositionAllYAxes()

End Sub

Private Sub PositionAllYAxes()

Dim i As Integer = 0

Do While i < chartControl1.Axes.Count

a = chartControl1.Axes(i)

If Not a Is chartControl1.PrimaryYAxis AndAlso a.Orientation = ChartOrientation.Vertical Then

a.LocationType = ChartAxisLocationType.Set

a.Location = New PointF(chartControl1.PrimaryYAxis.Location.X, chartControl1.PrimaryYAxis.Location.Y)

End If

End Sub

3. Then you have hide other axes in LayoutCompleted. Please refer to the following code snippet

C#

void chartControl1_LayoutCompleted(object sender, EventArgs e)

{

HideOtherAxes(a);

}

private void HideOtherAxes(ChartAxis currentAxis)

{

int axesCount = this.chartControl1.Axes.Count;

for (int i = 0; i < axesCount; i++)

{

ChartAxis a = this.chartControl1.Axes[i];

if (a != currentAxis && a.Orientation == ChartOrientation.Vertical)

{

a.DrawGrid = false;

a.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.None;

}

}

currentAxis.DrawGrid = true;

currentAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.AutomaticMode;

currentAxis.Location = new PointF(this.chartControl1.PrimaryYAxis.Location.X, this.chartControl1.PrimaryYAxis.Location.Y);

currentAxis.ZoomFactor = this.chartControl1.PrimaryYAxis.ZoomFactor;

}

VB

Private a As ChartAxis

Private Sub chartControl1_LayoutCompleted(ByVal sender As Object, ByVal e As EventArgs)

HideOtherAxes(a);

End Sub

Private Sub HideOtherAxes(ByVal currentAxis As ChartAxis)

Dim axesCount As Integer = Me.chartControl1.Axes.Count

Dim i As Integer = 0

Do While i < axesCount

Dim a As ChartAxis = Me.chartControl1.Axes(i)

If Not a Is currentAxis AndAlso a.Orientation = ChartOrientation.Vertical Then

a.DrawGrid = False

a.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.None

End If

i += 1

Loop

currentAxis.DrawGrid = True

currentAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.AutomaticMode

currentAxis.Location = New PointF(Me.chartControl1.PrimaryYAxis.Location.X, Me.chartControl1.PrimaryYAxis.Location.Y)

currentAxis.ZoomFactor = Me.chartControl1.PrimaryYAxis.ZoomFactor

End Sub

Sample: http://help.syncfusion.com/support/samples/Chart.Windows/HideYaxis/ChartSeries.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
95 04/30/2011 07/10/2014 WinForms Chart
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon