To add a doughnut chart, first add a data source to the worksheet:

using unvell.ReoGrid;
// ...

var worksheet = this.grid.CurrentWorksheet;

worksheet["A2"] = new object[,] {
 { null, 2008, 2009, 2010, 2011, 2012 },
 { "City A", 3, 2, 4, 2, 6 },
};

Define 2 ranges — a data source range and a title range — and add them to the highlight ranges collection:

var dataRange = worksheet.Ranges["B3:F3"];
var titleRange = worksheet.Ranges["B2:F2"];

worksheet.AddHighlightRange(dataRange);
worksheet.AddHighlightRange(titleRange);

Result:

429

Create the doughnut chart instance:

Chart.Chart c1 = new Chart.DoughnutChart
{
  Location = new Graphics.Point(30, 90),
  Size = new Graphics.Size(400, 260),

  Title = "Doughnut Chart Sample",
  DataSource = new Chart.WorksheetChartDataSource(worksheet,
    titleRange, dataRange, RowOrColumn.Column),
};

Add the chart instance to the worksheet; the chart will be displayed immediately:

worksheet.FloatingObjects.Add(c1);

Result:

428

Was this article helpful?