Free Support Forum -

Specifying the data that appears in the graph legend

We’re still evaluating the product and are pretty set to buy a licence for our website however we are attempting to create a graph at the moment and are having problems specifying the data that appears in the graph legend. It appears to be taking data from a non-specified column. Is there a way of specifying the column that the legend should take its data from?

Excel excel = new Excel();
Worksheet sheet = excel.Worksheets.GetAt(0);

Cells cells = sheet.Cells;
cells.GetAt(1,0).PutValue(“Company A”);
cells.GetAt(2,0).PutValue(“Company B”);
cells.GetAt(3,0).PutValue(“Company C”);

int chartIndex = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15);

Chart chart = sheet.Charts.GetAt(chartIndex);
chart.NSeries.Add(“B2:B4”, true);
chart.NSeries.CategoryData = “A2:A4”;

ASeries aSeries = chart.NSeries.GetAt(0);
aSeries.Name = “=B1”;
chart.IsLegendShown = true;
chart.Title.Text = “Income Analysis”;

[Visual Basic]
Dim excel As Excel = New Excel()
Dim sheet As Worksheet = excel.Worksheets.GetAt(0)

Dim cells As Cells = sheet.Cells
cells.GetAt(1,0).PutValue(“Company A”)
cells.GetAt(2,0).PutValue(“Company B”)
cells.GetAt(3,0).PutValue(“Company C”)

Dim chartIndex As Integer = sheet.Charts.Add(ChartType.Column,9,9,21,15)

Dim chart As Chart = sheet.Charts.GetAt(chartIndex)
chart.NSeries.Add(“B2:B4”, True)
chart.NSeries.CategoryData = “A2:A4”

Dim aSeries As ASeries = chart.NSeries.GetAt(0)
aSeries.Name = “=B1”
chart.IsLegendShown = True
chart.Title.Text = “Income Analysis”

excel.Save(“chart.xls”, SaveType.OpenInBrowser, FileFormatType.Default, Me.Response)