I know a similar issue was addressed a long time ago in this thread:
Hi,
Well, if you need to create non contiguous named ranges for chart’s data series, you may use Name object, see the topic for your reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/implementing-nonsequenced-ranges.html
Also, here is a sample code for your reference.
Sample code:
Dim _WorkBook As New Workbook()
_WorkBook.Worksheets.Clear()
_WorkBook.Worksheets.Add(SheetType.Worksheet)
Dim worksheet As Worksheet = _WorkBook.Worksheets(0)
worksheet.Name = “Series”
worksheet.Cells(0, 0).PutValue(“Anne”)
worksheet.Cells(0, 1).PutValue(“Srie A”)
worksheet.Cells(0, 2).PutValue(“Srie B”)
worksheet.Cells(1, 0).PutValue(“2006”)
worksheet.Cells(1, 1).PutValue(54)
worksheet.Cells(1, 2).PutValue(46)
worksheet.Cells(2, 0).PutValue(“2007”)
worksheet.Cells(2, 1).PutValue(15)
worksheet.Cells(2, 2).PutValue(85)
worksheet.Cells(3, 0).PutValue(“2008”)
worksheet.Cells(3, 1).PutValue(70)
worksheet.Cells(3, 2).PutValue(30)
Dim index As Integer = _WorkBook.Worksheets.Names.Add(“Data1”)
Dim name As Name = _WorkBook.Worksheets.Names(index)
'Creating a non sequence range of cells
name.RefersTo = “=Series!$B$2:$B$4,Series!$C$2:$C$4”
_WorkBook.Worksheets.Add(SheetType.Worksheet)
Dim chartsheet As Worksheet = _WorkBook.Worksheets(1)
chartsheet.Name = “Chart”
chartsheet.Charts.Add(ChartType.Column100PercentStacked, 0, 0, 25, 10)
Dim chart As Chart = chartsheet.Charts(0)
chart.PlotArea.Area.ForegroundColor = Color.Transparent
chart.Legend.Position = LegendPositionType.Bottom
chart.NSeries.Add(name.RefersTo,False)
chart.NSeries(0).XValues = “Series!A2:A4”
_WorkBook.Save(“e:\test2\outnonconti__test.xlsx”)
Thank you.
This method throws an invalid formula exception when I pass a multi-part cell reference containing a single quoted sheet name value with spaces.
Hi,
Well, it works similar to MS Excel. If a worksheet has spaces in its name, you have to enclose it within single quotes. This is same as Excel.
Could you create a sample console application to show the issue, we will check it soon.
Thank you.
I have found a solution for building these charts while writing you a test app to show the problem. By defining each column of each NSeries explicitly, I am able to chart the non-contiguous data cells. I also am not using any Name objects at all.