Excel Chart issues  
Author Message
black_knight_27





PostPosted: Visual Basic General, Excel Chart issues Top

How do I create an Excel chart in VB.NET.

Here's the guidelines:

series1:  C6:C22

X Value: A6:A22

as Column clustered

and I would like to add a horizontal line accross it that is = C6

 

I'm new to VB.Net ...the following VBA is what was given in the macro I'm trying to decode.  Can anyone help me flip the VBA into VB.net without using a lot of shortcuts and implied imported paths

 

'AvgAuxTimeChart.Creator()

'ExcelChartSheet.Sheets("Charts").Select()

'ExcelChartSheet.Application.Charts.Add()

'Dim AvgAuxTimeChart As Excel.Charts

'AvgAuxTimeChart.ChartType = xlColumnClustered()

'AvgAuxTimeChart.SetSourceData(Source:=ExcelChartSheet.Sheets("Charts").Range("A1"))

'AvgAuxTimeChart.SeriesCollection.NewSeries()

'AvgAuxTimeChart.SeriesCollection.NewSeries()

'AvgAuxTimeChart.SeriesCollection(1).XValues = "=ITCSC!R6C1:R22C1"

'AvgAuxTimeChart.SeriesCollection(1).Values = "=ITCSC!R6C3:R22C3"

'AvgAuxTimeChart.SeriesCollection(2).Values = "=ITCSC!R6C16:R22C16"

'AvgAuxTimeChart.Location(Where:=Excel.XlChartLocation.xlLocationAsNewSheet)

'ExcelChartSheet.Application.Charts.Add()

'AvgAuxTimeChart.SeriesCollection(2).Select()

'AvgAuxTimeChart.SeriesCollection(2).ChartType = xlXYScatterLinesNoMarkers

'AvgAuxTimeChart.Legend.Select()

'AvgAuxTimeChart.Selection.Delete()

'AvgAuxTimeChart.PlotArea.Select()

'AvgAuxTimeChart.HasTitle = True

'AvgAuxTimeChart.ChartTitle.Characters.Text = "Averave Talk Time"

'AvgAuxTimeChart.PlotArea.Select()

'AvgAuxTimeChart.Selection.Border.ColorIndex = 16

'AvgAuxTimeChart.Selection.Border.Weight = xlThin

'AvgAuxTimeChart.Selection.Border.LineStyle = xlContinuous

'AvgAuxTimeChart.Selection.Fill.TwoColorGradient(Style:=msoGradientHorizontal, Variant:=1)

'AvgAuxTimeChart.Selection.Fill.Visible = True

'AvgAuxTimeChart.Selection.Fill.ForeColor.SchemeColor = 3

'AvgAuxTimeChart.Selection.Fill.BackColor.SchemeColor = 2

'AvgAuxTimeChart.SeriesCollection(2).Select()

'AvgAuxTimeChart.Selection.Border.ColorIndex = 5

'AvgAuxTimeChart.Selection.Border.Weight = xlThick

'AvgAuxTimeChart.Selection.Border.LineStyle = xlContinuous

'AvgAuxTimeChart.Selection.MarkerBackgroundColorIndex = xlNone

'AvgAuxTimeChart.Selection.MarkerForegroundColorIndex = xlNone

'AvgAuxTimeChart.Selection.MarkerStyle = xlNone

'AvgAuxTimeChart.Selection.Smooth = False

'AvgAuxTimeChart.Selection.MarkerSize = 5

'AvgAuxTimeChart.Selection.Shadow = False

 

 

This is what I currently have:

Dim ExcelChartSheet As Excel.Worksheet = TheWorkBook.Sheets.Add()

ExcelChartSheet = TheWorkBook.ActiveSheet

ExcelChartSheet.Name = "Charts"

ExcelChartSheet.Range("a1:bb150").Interior.ColorIndex = 15 'gray

ExcelChartSheet.Move(after:=ExcelSheet)

 

Dim charts As Excel.ChartObjects = CType(ExcelChartSheet.ChartObjects(), Excel.ChartObjects)

Dim chartObj As Excel.ChartObject = charts.Add(0, 0, 800, 500)

Dim chrtAvgAuxTime As Excel.Chart = chartObj.Chart

'Dim chartRange As Excel.Range = ExcelSheet.Range("c7:c" & RowNumber - 1)

'chrtAvgAuxTime.SetSourceData(chartRange)

chrtAvgAuxTime.ChartType = Excel.XlChartType.xlColumnClustered

Dim series As Excel.Series

Dim seriesCollection As Excel.SeriesCollection = CType(chrtAvgAuxTime.SeriesCollection(), Excel.SeriesCollection)

series = seriesCollection.Item(seriesCollection.Count)

 

 

 

Any help would be very gracoiusly appreciated.



Visual Basic21