Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Tables
    [Expand]Pivot Tables
    [Expand]Printing
    [Expand]Pictures
    [Collapse]Charts
      How to: Create a Basic Chart
      How to: Format Chart Elements
      How to: Display the Chart Title
      How to: Display and Format Data Labels
      How to: Show or Hide the Chart Legend
      How to: Change the Display of Chart Axes
      How to: Protect a Chart
    [Expand]Protection
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Create a Basic Chart

This example demonstrates how to use the Spreadsheet Chart API to create a basic chart and specify its settings.

To improve the control's performance by avoiding unnecessary render operations after each modification, enclose the chart modifications in the Workbook.BeginUpdate() - Workbook.EndUpdate() method pair.

Select the action you wish to perform.

Expanded Add and Position a Chart

All charts embedded in a worksheet are stored in the chart collection accessible using the Worksheet.Charts property. To create a chart, add it to the chart collection by utilizing the ChartCollection.Add method and pass the following parameters: the required chart type (ChartType) and the Range object containing data for the chart (this parameter is optional and can be omitted, so you can manually add data series to your chart).

To position the created chart in a worksheet, use one of the following approaches.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

The example below demonstrates how to create a 3-D pie chart using the ChartCollection.Add method overload that enables you to specify a Range containing chart data.

Expanded Add or Remove Data Series

If you did not specify the range containing chart data in the ChartCollection.Add method, you can define it later by using one of the following approaches.

  • Pass the required data range to the Chart.SelectData method. You can also specify the direction in which data should be plotted along the axes. For example, if you wish to display columns of data along the category axis, use the ChartDataDirection.Column value as the direction parameter.

  • Utilize the SeriesCollection.Add method to plot a data series on your chart. Using this method, you can fully control the number of series on your chart and explicitly specify data that should be plotted along the category and value axes. Moreover, this method is extremely useful if you wish to plot data contained in noncontiguous ranges. For example, you can plot a data series with arguments from Column B and values from the Column D.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

To remove an individual series from the chart, use the SeriesCollection.Remove or SeriesCollection.RemoveAt method.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

The example below demonstrates how to remove the second series from the chart.

Expanded Change Chart Data References

After you create a chart, you can change the cell range from which data for the series arguments and values is retrieved. To do this, perform the steps below.

  1. Use the ChartData.FromRange method to create the ChartData object containing new data for the series.

  2. Assign the created object to the Series.Arguments or Series.Values property.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

The example below demonstrates how to add data series to a chart and change the cell range containing data for a specific series.

The code uses the SeriesCollection.Add method to create a series and add it to the Chart.Series collection. To specify series values contained in the worksheet range, create a ChartData object using the ChartData.FromRange method and assign it to the Series.Values property.

The ChartText.SetReference method is used to link the Series.SeriesName to the content of the worksheet cell.

Expanded Change the Order of Data Series

By default, if your chart has multiple data series, they are plotted on a chart in the order they appear on a worksheet (from left to right if data is arranged in columns, or from top to bottom if data is arranged in rows). However, you can change this default order. Utilize the Series.BringForward or Series.SendBackward method to move the specified series up or down in the plotting order, one position at a time. To place the series before or behind all other series on a chart, use the Series.BringToFront or Series.SendToBack method.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

Expanded Change the Chart Type

After you created a chart, you may find that the chart you selected is not suitable and another chart type may better represent your data. In this case, there is no need to recreate the chart. Simply change the type of the entire chart using the Chart.ChangeType method. This method substitutes the existing chart with the chart you specified. If the operation cannot be completed, an exception is fired.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

The example below demonstrates how to create a chart of the ChartType.PieExploded type. After that, the code attempts to change the chart type to ChartType.LineMarker using the Chart.ChangeType method. If you try to change the chart type to ChartType.StockHighLowClose (this line is commented), an exception will be thrown, because the data range is insufficient for this chart type, and the chart will be changed to ChartType.ColumnClustered.

Expanded Change the Chart Type of a Series (Combination Chart)

Besides changing a type of the entire chart, you can also select a different chart type for an individual data series. This will automatically turn the chart into a combination chart. A combination chart is a complex chart that consists of two or more ChartView objects that consolidate series of the same chart type. To change the type of a single data series, call the Series.ChangeType method. If the series type you specified differs from the types of the existing ChartView objects (ChartView.ViewType), a new ChartView containing your series will be created, otherwise, the series will be added to the existing ChartView of the same type.

Important

Not all chart types can be combined (for example, it is impossible to combine the 2-D and 3-D chart types). If you select a type that does not logically connect with the existing chart type, the resulting chart will contain only one ChartView of the most recently added type.

Compatible chart types are listed below.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E5222.

How would you rate this topic?​​​​​​​