Syncfusion.XlsIO.Base
Example 


PivotSource Property

Gets or sets the pivot source.
Syntax
'Declaration
 
Property PivotSource As IPivotTable
'Usage
 
Dim instance As IChart
Dim value As IPivotTable
 
instance.PivotSource = value
 
value = instance.PivotSource
IPivotTable PivotSource {get; set;}

Property Value

The pivot source
Remarks
To know more about pivot tables refer Working with Pivot Tables.
Example
The following code illustrates how to set data source for the PivotSource property.
using Syncfusion.XlsIO;
using System.Data;
            
class Program
{
    static void Main(string[] args)
    {
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
            //Create worksheet
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook = application.Workbooks.Create(1);
            IWorksheet sheet = workbook.Worksheets[0];
            
            //Add data
            sheet.ImportDataTable(getData(), true, 1, 1);
            
            //Create pivot table
            IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
            IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
            pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
            pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
            pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
            IPivotField field = pivotTable.Fields[3];
            pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
            
            //Create chart
            IChart chart = sheet.Charts.Add();
            
            //Set pivot source
            chart.PivotSource = pivotTable;
            
            //Save and Dispose
            workbook.SaveAs("Chart.xlsx");
            workbook.Close();
        }
    }
    static DataTable getData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Region");
        dt.Columns.Add("Employee");
        dt.Columns.Add("Item");
        dt.Columns.Add("Units");
        dt.Rows.Add("Central", "Jones", "Pen Set", 700);
        dt.Rows.Add("West", "Kivell", "Binder", 85);
        dt.Rows.Add("East", "Gill", "Pen", 58);
        dt.Rows.Add("Central", "Jones", "Pen Set", 46);
        dt.Rows.Add("West", "Kivell", "Binder", 61);
        dt.Rows.Add("Central", "Jones", "Pen", 90);
        dt.Rows.Add("West", "Kivell", "Pen Set", 32);
        dt.Rows.Add("East", "Gill", "Binder", 79);
        dt.Rows.Add("Central", "Jones", "Pen Set", 27);
        dt.Rows.Add("Central", "Jones", "Binder", 5);
        dt.Rows.Add("East", "Gill", "Pen Set", 41);
        dt.Rows.Add("East", "Gill", "Pen Set", 61);
        dt.Rows.Add("East", "Gill", "Binder", 9);
        dt.Rows.Add("Central", "Jones", "Pen Set", 75);
        dt.Rows.Add("West", "Kivell", "Pen Set", 97);
        dt.Rows.Add("West", "Kivell", "Pen Set", 86);
        dt.Rows.Add("East", "Gill", "Pen Set", 90);
        dt.Rows.Add("East", "Gill", "Pen Set", 25);
        dt.Rows.Add("East", "Gill", "Binder", 68);
        dt.Rows.Add("East", "Gill", "Binder", 19);
        return dt;
    }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 17.2460.0.34

See Also