2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
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); } } } VBAddHandler 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; } VBPrivate 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 |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.