ReoGrid supports various chart types that can be displayed on worksheets as floating objects. Charts update automatically when their data source changes, and they are saved/loaded with Excel files.

Namespace

using unvell.ReoGrid.Chart;
using unvell.ReoGrid.Drawing;

Available Chart Types

ClassSampleDescription
ColumnChart238Vertical bar chart
BarChart274Horizontal bar chart
LineChart235Line chart
AreaChart341Filled area chart
Pie2DChart2392D pie chart
DoughnutChart430Doughnut chart

Creating a Chart

Step 1: Prepare Data

var sheet = grid.CurrentWorksheet;

sheet["A2"] = new object[,] {
    { null, 2008, 2009, 2010, 2011, 2012 },
    { "City 1", 3, 2, 4, 2, 6 },
    { "City 2", 7, 5, 3, 6, 4 },
    { "City 3", 13, 10, 9, 10, 9 },
};

Step 2: Define Ranges

var dataRange = sheet.Ranges["B3:F5"];           // The numeric data
var serialNamesRange = sheet.Ranges["A3:A5"];    // Series names (row headers)
var categoryNamesRange = sheet.Ranges["B2:F2"];  // Category names (column headers)

Step 3: Create the Chart

var chart = new ColumnChart
{
    Location = new Graphics.Point(220, 160),
    Size = new Graphics.Size(400, 260),
    Title = "Column Chart Sample",
    DataSource = new WorksheetChartDataSource(sheet, serialNamesRange, dataRange)
    {
        CategoryNameRange = categoryNamesRange,
    },
};

Step 4: Add to Worksheet

sheet.FloatingObjects.Add(chart);

Chart Properties

All chart types inherit from the Chart base class:

PropertyTypeDefaultDescription
Titlestring"Chart"Chart title text
DataSourceWorksheetChartDataSourcenullThe chart’s data source
ShowLegendbooltrueWhether to show the legend
PrimaryLegendChartLegendβ€”The chart’s legend instance
DataSerialStylesDataSerialStyleCollectionβ€”Styles for each data series
LocationGraphics.Pointβ€”Top-left position on the worksheet
SizeGraphics.Sizeβ€”Width and height
BoundsGraphics.Rectangleβ€”Position and size combined
VisiblebooltrueWhether the chart is visible

Events

EventDescription
ChartDataChangedRaised when chart data is updated
DataSourceChangedRaised when the data source is changed

Data Source

WorksheetChartDataSource

Connects worksheet data to a chart:

// Constructor with ranges
var dataSource = new WorksheetChartDataSource(sheet, serialNamesRange, dataRange)
{
    CategoryNameRange = categoryNamesRange,
};

// Constructor with string addresses
var dataSource = new WorksheetChartDataSource(sheet, "A3:A5", "B3:F5")
{
    CategoryNameRange = sheet.Ranges["B2:F2"],
};

Constructors

ConstructorDescription
WorksheetChartDataSource(worksheet)Empty data source
WorksheetChartDataSource(worksheet, serialNamesRange, dataRange)With series names and data ranges
WorksheetChartDataSource(worksheet, serialNamesRange, dataRange, rowOrColumn)Specify whether series are in rows or columns

Properties

PropertyTypeDescription
WorksheetWorksheetThe worksheet containing the data
CategoryNameRangeRangePositionRange containing category labels
SerialCountintNumber of data series (read-only)
CategoryCountintNumber of categories (read-only)
SerialsWorksheetChartDataSerialCollectionCollection of data series

Methods

MethodDescription
GetCategoryName(int index)Get category label by index
AddSerial(worksheet, labelAddress, dataRange)Add a data series manually
GetSerial(int index)Get a specific data series

Events

EventDescription
DataChangedRaised when the source data changes

WorksheetChartDataSerial

Represents one data series in the chart:

PropertyTypeDescription
WorksheetWorksheetThe worksheet containing the data
DataRangeRangePositionRange containing the series data
LabelAddressCellPositionAddress of the series label cell
LabelstringSeries name (read-only)
CountintNumber of data points (read-only)
this[int index]double?Get data value by index

Data Series Styles

Customize the appearance of each data series:

// Access styles by index
var style = chart.DataSerialStyles[0];
PropertyTypeDefaultDescription
FillColorIColor(auto)Fill color for bars, areas, pie slices
LineColorSolidColor(auto)Line color for line charts
LineWidthRGFloat2fLine width
LineStyleLineStylesSolidLine style (Solid, Dash, Dot, etc.)
StartCapLineCapStylesNoneStart cap style
EndCapLineCapStylesNoneEnd cap style

Example: Semi-Transparent Area Chart

foreach (var style in chart.DataSerialStyles)
{
    style.FillColor = new Graphics.SolidColor(100, style.FillColor.ToSolidColor());
}

Legend

Control the chart legend:

// Hide the legend
chart.ShowLegend = false;

// Access legend properties
var legend = chart.PrimaryLegend;

LegendPosition Enum

ValueDescription
RightLegend on the right side (default)
BottomLegend at the bottom
LeftLegend on the left side
TopLegend at the top

Axis Configuration (Axis Charts Only)

Column, Bar, Line, and Area charts inherit from AxisChart and support axis configuration:

PropertyTypeDescription
PrimaryAxisInfoAxisDataInfoPrimary axis configuration
SecondaryAxisInfoAxisDataInfoSecondary axis configuration
ShowHorizontalGuideLinesboolShow horizontal guide lines (default: true)
ShowVerticalGuideLinesboolShow vertical guide lines (default: false)

AxisDataInfo Properties

PropertyTypeDescription
LevelsintNumber of axis levels
ScalerintAxis scaler
MinimumdoubleAxis minimum value
MaximumdoubleAxis maximum value
AutoMinimumboolAutomatically determine minimum
AutoMaximumboolAutomatically determine maximum
LargeStridedoubleLarge stride value (major gridlines)
SmallStridedoubleSmall stride value (minor gridlines)

Highlight Ranges

Highlight the data ranges on the worksheet to visually indicate the chart’s data source:

sheet.AddHighlightRange(dataRange);
sheet.AddHighlightRange(serialNamesRange);
sheet.AddHighlightRange(categoryNamesRange);

Chart Type Details

Chart TypeDocumentation
Column ChartColumn Chart
Bar ChartBar Chart
Line ChartLine Chart
Area ChartArea Chart
Pie 2D ChartPie 2D Chart
Doughnut ChartDoughnut Chart

Class Hierarchy

FloatingObject
  └─ DrawingObject
      └─ DrawingComponent
          └─ Chart (base)
              β”œβ”€ AxisChart
              β”‚   β”œβ”€ ColumnChart
              β”‚   β”‚   └─ BarChart
              β”‚   β”œβ”€ LineChart
              β”‚   └─ AreaChart
              └─ PieChart
                  β”œβ”€ Pie2DChart
                  └─ DoughnutChart
Was this article helpful?