# How do I sync the X-axis of multiple charts?

## Content



In applications that show multiple charts, you can sync the ticks on the x-axis of each chart.

Use the [Margins](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.Area.Margins.html) property to align the axis positions of several chart areas. For example, the following method arranges the x-axis positions for two charts. Note that it can also be modified for syncing three charts.

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
Private Sub AdjustAxisPositions() 
    C1Chart1.ChartArea.Margins.Left = 10 
    C1Chart1.ChartArea.Margins.Right = 10 
    C1Chart2.ChartArea.Margins.Left = 10 
    C1Chart2.ChartArea.Margins.Right = 10 
    ' force redrawing 
    Dim img As Image = C1Chart1.GetImage() 
    If img IsNot Nothing Then 
        img.Dispose() 
    End If 
    img = C1Chart2.GetImage()   
    If img IsNot Nothing Then 
        img.Dispose()   
    End If     
    Dim ch1_X As Rectangle = C1Chart1.ChartArea.AxisX.GetAxisRect()  
    Dim ch2_X As Rectangle = C1Chart2.ChartArea.AxisX.GetAxisRect() 
    Dim d As Integer = ch1_X.Left - ch2_X.Left  
    If d > 0 Then 
        C1Chart2.ChartArea.Margins.Left += d 
        ElseIf d < 0 Then 
                c1Chart1.ChartArea.Margins.Left -= d 
    End If 
    d = ch1_X.Right - ch2_X.Right 
    If d > 0 Then 
        C1Chart1.ChartArea.Margins.Right += d 
        ElseIf d < 0 Then 
        C1Chart2.ChartArea.Margins.Right -= d 
    End If 
End Sub
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
void AdjustAxisPositions() 
{    
        c1Chart1.ChartArea.Margins.Left = 10;      
        c1Chart1.ChartArea.Margins.Right = 10;    
        c1Chart2.ChartArea.Margins.Left = 10;  
        c1Chart2.ChartArea.Margins.Right = 10;     
        // force redrawing    
        Image img = c1Chart1.GetImage();
        if( img!=null)
                img.Dispose();
        img = c1Chart2.GetImage();
        if( img!=null)
                img.Dispose();     
        Rectangle ch1_X = c1Chart1.ChartArea.AxisX.GetAxisRect();  
        Rectangle ch2_X = c1Chart2.ChartArea.AxisX.GetAxisRect();
        int d = ch1_X.Left - ch2_X.Left;
        if( d>0)    
                c1Chart2.ChartArea.Margins.Left += d;
        else if( d<0)    
                c1Chart1.ChartArea.Margins.Left -= d;    
                d = ch1_X.Right - ch2_X.Right;  
        if( d>0)    
                c1Chart1.ChartArea.Margins.Right += d;   
        else if( d<0)   
                c1Chart2.ChartArea.Margins.Right -= d; 
}
```

DOC-DETAILS-TAG-CLOSE