How do I display years across the x-axis

Hello,
I am using the following code to create a graph in a excel worksheet from vb.net.  The code preceding the code listed below creates the table from which the graph is dereived.  I'm having trouble having the years appear on the x-axis .  
Dim oChart As Excel.Chart
                    Dim MyCharts As Excel.ChartObjects
                    Dim MyCharts1 As Excel.ChartObject
                    MyCharts = excelSheet.ChartObjects
                    'set chart location
                    MyCharts1 = MyCharts.Add(150, 290, 400, 250)

                    oChart = MyCharts1.Chart
                    'use the follwoing line if u want 
                    'to draw chart on the default location
                    'oChart.Location(Excel.XlChartLocation.xlLocationAsObject, excelSheet.Name)


                    Dim R As Integer = datTable.Rows.Count + 1
                    'MessageBox.Show(R.ToString)
                    With oChart
                        'set data range for chart
                        Dim chartRange As Excel.Range
                        chartRange = excelSheet.Range("A1", "N" & R)
                        'MessageBox.Show(excelSheet.Range("A2").Value.ToString)
                        .SetSourceData(chartRange)
                        'set how you want to draw chart i.e column wise or row wise

                        '.PlotBy = Excel.XlRowCol.xlColumns

                        .PlotBy = Excel.XlRowCol.xlRows

                        .SeriesCollection(1).Delete()
                        'set data lables for bars
                        .ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowNone)


                        'set legend to be displayed or not
                        .HasLegend = True
                        'set legend location
                        .Legend.Position = Excel.XlLegendPosition.xlLegendPositionRight
                        'select chart type
                        .ChartType = Excel.XlChartType.xlLine
                        'chart title
                        .HasTitle = True
                        .ChartTitle.Text = "Test"
                        'set titles for Axis values and categories
                        Dim xlAxisCategory, xlAxisValue As Excel.Axes
                        xlAxisCategory = CType(oChart.Axes(, Excel.XlAxisGroup.xlPrimary), Excel.Axes)
                        xlAxisCategory.Item(Excel.XlAxisType.xlCategory).HasTitle = True
                        xlAxisCategory.Item(Excel.XlAxisType.xlCategory).AxisTitle.Characters.Text = "Forecast Years"

                        xlAxisValue = CType(oChart.Axes(, Excel.XlAxisGroup.xlPrimary), Excel.Axes)


                        xlAxisValue.Item(Excel.XlAxisType.xlValue).HasTitle = True
                        xlAxisValue.Item(Excel.XlAxisType.xlValue).AxisTitle.Characters.Text = "Metrics"
                        
                        'oChart.SeriesCollection(1).Delete()
                        MessageBox.Show("Chart Completed")
                    End With
                    'MyCharts1.BringToFront()
                    'Set file format number to 56 if excel version <> 2007 
                    If Not filename.EndsWith(".xlsx") Then
                        excelWorkbook.SaveAs(filename, 56)

                    Else
                        excelWorkbook.SaveAs(filename)
                    End If

                    MsgBox("File generated successfully at " & filename)

                End If
            End If

Open in new window

test.xlsx
Juan VelasquezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Hello chtullu,

you need to include the .XValues property in your chart definition

    ActiveChart.SeriesCollection(1).XValues = "=Sheet1!$F$1:$N$1"

cheers, teylyn

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Juan VelasquezAuthor Commented:
The solution helped.  Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.