0
votes

Before saying this has been answered numerous times, don't please. I have looked at every link I could find. I still am having trouble figuring it out because most answers talk about VBA IN Excel not VB.Net in Visual Studio.

I am trying this:

    Dim Charts As Excel.ChartObjects = CType(sheet.ChartObjects(Type.Missing), Excel.ChartObjects)
    Dim myChart As Excel.ChartObject = CType(Charts.Add(10, pos * 20, 600, 400), Excel.ChartObject)
    Dim chart As Excel.Chart = myChart.Chart
    chart.ChartType = Excel.XlChartType.xlLineStacked

    chart.SetSourceData(sheet.Range("B4:B10, E4:E10"))
    chart.SetSourceData(sheet.Range("H4:H10, J4:J10"))

It plots 1 series perfectly, but I can't get the second series on there. The chart displays like this: I tried creating a Macro in Excel and then pasting/editing the code and I couldn't get that to work either. Working with VB.Net and Excel is all new to me. How can I plot multiple series to an Excel sheet from VB.Net? Thanks!!

1

1 Answers

0
votes

UPDATE:

I was able to FINALLY figure this out. I wasn't creating a separate series individually. Now I feel like this was a really dumb question... Thanks everyone. This is what I did to get it working.

    Dim ds As Excel.Series
    ds = chart.SeriesCollection.NewSeries()
    ds.XValues = sheet.Range("B4:B6")
    ds.Values = sheet.Range("E4:E6")