Skip to main content
All docs
V26.1
  • ChartBase.Data Property

    Provides access to the underlying spreadsheet that stores the chart data.

    Namespace: DevExpress.Docs.Presentation

    Assembly: DevExpress.Docs.Presentation.v26.1.dll

    Declaration

    public ChartData Data { get; }

    Property Value

    Type Description
    ChartData

    The chart data.

    Remarks

    Use the Data indexer to access individual cells and set their values. The indexer accepts a sheet index and a cell reference string, and returns a CellValue object.

    Set the CellValue.NumericValue, CellValue.DateTimeValue, CellValue.BooleanValue or CellValue.TextValue property to specify the cell value.

    After you populate cells, create a ChartDataReference that points to the cell range and assign it to the series Arguments and Values properties.

    Charts accept cell references in A1 style.

    The following code snippet loads chart data from the embedded spreadsheet cells to a series:

    using DevExpress.Docs.Office;
    using DevExpress.Docs.Presentation;
    using System.Drawing;
    
    namespace PresentationApiSample;
    
    public class Program {
        public static async Task Main(string[] _) {
    
            // Create a presentation.
            Presentation presentation = new Presentation();
    
            // Reset the slide collection.
            presentation.Slides.Clear();
    
            // Add a blank slide.
            Slide slide = new Slide(SlideLayoutType.Blank);
            presentation.Slides.Add(slide);
    
            // Insert a chart that fills the slide.
            Chart chart = new Chart();
            chart.Width = presentation.SlideSize.Width;
            chart.Height = presentation.SlideSize.Height;
            slide.Shapes.Add(chart);
    
            // Populate chart data.
            chart.Data[0, "A1"].NumericValue = 120;
            chart.Data[0, "A2"].NumericValue = 95;
            chart.Data[0, "A3"].NumericValue = 140;
            chart.Data[0, "B1"].TextValue = "Q1";
            chart.Data[0, "B2"].TextValue = "Q2";
            chart.Data[0, "B3"].TextValue = "Q3";
    
            // Bind series values and arguments to chart data ranges.
            BarSeries series = new BarSeries();
            series.Values = new ChartDataReference(sheetIndex: 0, fromCellReference: "A1", toCellReference: "A3");
            series.Arguments = new ChartDataReference(sheetIndex: 0, fromCellReference: "B1", toCellReference: "B3");
    
            // Add the series to the chart.
            chart.Series.Add(series);
    
            // Set chart title formatting.
            chart.Title = new ChartTitle(new TextArea { 
                Text = "Chart Title", 
                Level1ParagraphProperties = new TextParagraphProperties { 
                    TextProperties = new TextProperties { FontSize = 30, Fill = new SolidFill(Color.DarkBlue) }
                }
            });
        }
    }
    

    For additional infromation on how to load data into a chart, refer to the following help topic: Load Data to Charts with DevExpress Presentation API.

    See Also