Search results

Pivot Chart in ASP.NET Core Pivot Table control

In pivot table component, pivot chart would act as an additional visualization component with its basic and important characteristic like drill down and drill up, 15+ chart types, series customization, axis customization, legend customization, export, print and tooltip. Its main purpose is to show the pivot data in graphical format.

If user prefers, the pivot chart component can also be displayed individually with pivot values and can change the report dynamically with the help of field list and grouping bar. Using the e-displayOption property in ejs-pivotview tag, user can set the visibility of grid and chart in pivot table component. It holds below properties,

  • view: Specifies the pivot table component to display grid alone or chart alone or both.
  • primary: Specifies the pivot table to display either grid or chart as primary component during initial loading. It is applicable only when setting the property view to Both.

The below sample displays the pivot chart component based on the pivot report bound on it.

tagHelper
DisplayView.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

Data Binding

End user can bind both local and remote data binding options available in the component to feed the data. The dataSource property can be assigned either with an instance of DataManager or list of object. For more information refer here.

Chart Types

Supports 19 different types of charts as follows,

  • Line
  • Column
  • Area
  • Bar
  • StepArea
  • StackingColumn
  • StackingArea
  • StackingBar
  • StepLine
  • Pareto
  • Bubble
  • Scatter
  • Spline
  • SplineArea
  • StackingColumn100
  • StackingBar100
  • StackingArea100
  • Polar
  • Radar

Line is the default pivot chart type. User can change the pivot chart type by using the property type in e-chartSeries tag.

In the below code sample, the pivot chart type is set as Bar.

tagHelper
ChartType.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Accumulation Charts

Supports 4 different types of accumulation charts as follows,

  • Pie
  • Doughnut
  • Funnel
  • Pyramid

As like other chart types it can be changed using the property type in e-chartSeries tag.

In the below code sample, the Pie chart is rendered, and the other accumulation charts can be switched using the drop-down list.

tagHelper
Accumulation.cs
<div class="control-section" style="overflow:auto">
    <div id="dropdown-control" style="margin-bottom:5px;">
        <table style="width: 350px;">
            <tbody>
                <tr style="height: 50px">
                    <td>
                        <div>
                            <b>Chart Type:</b>
                        </div>
                    </td>
                    <td>
                        <div>
                            <select id="charttype" name="ddl-view-mode">
                                <option value='Pie' selected>Pie</option>
                                <option value='Doughnut'>Doughnut</option>
                                <option value='Pyramid'>Pyramid</option>
                                <option value='Funnel'>Funnel</option>
                            </select>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="content-wrapper">
        <ejs-pivotview id="Pivotview" height="300">
            <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
                <e-rows>
                    <e-field name="Country"></e-field>
                    <e-field name="Products"></e-field>
                </e-rows>
                <e-columns>
                    <e-field name="Year"></e-field>
                    <e-field name="Quarter"></e-field>
                </e-columns>
                <e-values>
                    <e-field name="Sold" caption="Units Sold"></e-field>
                    <e-field name="Amount" caption="Sold Amount"></e-field>
                </e-values>
                <e-formatsettings>
                    <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
                </e-formatsettings>
            </e-datasourceSettings>
            <e-chartSettings title="Sales Analysis">
                <e-chartSeries type="Pie"></e-chartSeries>
            </e-chartSettings>
            <e-displayOption view="Chart"></e-displayOption>
        </ejs-pivotview>
    </div>
</div>
<script>
    var chartDropDown = new ej.dropdowns.DropDownList({
        change: function (args) {
            var pivotObj = document.getElementById('pivotview').ej2_instances[0];
            pivotObj.chartSettings.chartSeries.type = args.value;
        }
    });
    chartDropDown.appendTo('#charttype');
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Drill Down/Up

In the accumulation charts, drill down and drill up operations can be performed using the built-in context menu option. It will be shown while clicking on the chart series. The context menu has the following options: Expand - It is to drill down the corresponding series until the last level. Collapse - It is to drill up the corresponding series until the first level. Exit - It is to close the context menu.

The drill operation in accumulation charts can be performed only for row headers.

tagHelper
Drill.cs
<ejs-pivotview id="pivotview" height="300">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Products"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis">
        <e-chartSeries type="Pie"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Column Headers and Delimiters

Unlike other chart types, the accumulation charts consider the values of a single column from the pivot table to be drawn. Preferably the first column of the pivot table is considered by default. But it can be changed by defining the column headers using the columnHeader property in e-chartSettings tag.

If the column has more than one header, then need to mention all the headers separated by the delimiter -, for example,FY 2016-Q2. Using the property columnDelimiter in e-chartSettings tag, one can set the desired delimiter to separate the column headers.

Using the property columnDelimiter in chartSettings, one can set the desired delimiter to separate the column headers.

tagHelper
Column.cs
<ejs-pivotview id="pivotview" height="300">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-drilledmembers>
            <e-field name="Year" items="@(new string[] { "FY 2016" })"></e-field>
        </e-drilledmembers>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis" columnHeader="@(new string[] { "FY 2016-Q2" })" columnDelimiter="-">
        <e-chartSeries type="Doughnut"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Label Customization

The data labels are visible by default showing header name. Its visibility can be modified using the visible boolean property in dataLabel. With regard to the label arrangement, the Smart Labels options help to arrange labels efficiently without overlapping. It can be disabled by setting the enableSmartLabels property in e-chartSettings tag as false. The position property in dataLabel allows to specify the position of the data label. The available options are,

  • Outside: Positions the label outside the point. It is the default option.
  • Inside: Positions the label inside the point.

In the following code sample, the data labels are placed inside.

tagHelper
DataLabel.cs
<ejs-pivotview id="pivotview" height="300">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Year"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Country"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis" enableSmartLabels="false">
        <e-chartSeries type="Pyramid">
            <e-datalabel position="@ViewBag.position"></e-datalabel>
        </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    ViewBag.position = Position;
    return View();
}

public PivotViewPivotChartDataLabel Position = new PivotViewPivotChartDataLabel { Position = "Inside" };

output

The Connector Line will be visible when the data label is placed outside the chart. It can be customized using the connectorStyle property in dataLabel for its color, length, width etc. In the following code sample, the connector line is customized.

tagHelper
Connector.cs
<ejs-pivotview id="pivotview" height="300">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Year"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Country"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis" enableSmartLabels="true">
        <e-chartSeries type="Funnel">
            <e-datalabel position="@ViewBag.position">
                <e-connectorStyle color="#f4429e" dashArray="5,3" length="50px" width="2"></e-connectorStyle>
            </e-datalabel>       
         </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    ViewBag.position = Position;
    return View();
}

public PivotViewPivotChartDataLabel Position = new PivotViewPivotChartDataLabel { Position = "OutSide" };

output

Pie and Doughnut Customization

User can draw pie and doughnut charts within the specified range using the startAngle and endAngle properties in e-chartSeries tag. The default value of the startAngle property is 0, and the endAngle property is 360. By customizing these properties, user can draw semi pie and semi doughnut charts.

tagHelper
Angle.cs
<ejs-pivotview id="pivotview" height="300">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Year"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Country"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis">
        <e-chartSeries type="Doughnut" startAngle="270" endAngle="90">
        </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Users can get doughnut chart from pie chart and vice-versa using the innerRadius property in e-chartSeries tag. If the property is greater than 0 percent, the doughnut chart will appear from the pie chart.

It takes the value only in percentage.

tagHelper
Radius.cs
<ejs-pivotview id="pivotview"  height="300" >
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Year"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Country"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis" load="onChartLoad" >
        <e-chartSeries type="Pie" innerRadius="140">
        </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Exploding Series Points

Exploding can be enabled by setting the explode property in e-chartSeries tag to true. The series points will be exploded either on mouse click or touch.

tagHelper
Explode.cs
<ejs-pivotview id="pivotview" height="300">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Year"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Country"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis">
        <e-chartSeries type="Pie" explode="true">
        </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Field List

User can enable the field list by setting the property showFieldList in ejs-pivotview tag as true. By using this, user can customize the report dynamically and view the result in pivot chart. For more information regarding the field list, refer the field list topic.

In the following sample, the Popup mode of field list is enabled in the pivot chart integration.

tagHelper
ChartFieldList.cs
<ejs-pivotview id="PivotView" height="300" showFieldList="true">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Grouping Bar

User can enable the grouping bar by setting the property showGroupingBar in ejs-pivotview tag as true. The grouping bar in pivot chart shows a dropdown list in value axis instead of buttons. The dropdown list holds list of value fields bounded in the e-datasourcesettings and it can be switched to draw the pivot chart with the selected value field. This has been defined as the default behavior in the pivot chart component. For more information regarding the grouping bar, refer the grouping bar topic.

For multiple axis support, buttons will be placed in value axis instead of dropdown list.

tagHelper
<ejs-pivotview id="PivotView" height="300" showGroupingBar="true">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>

output

For accumulation charts alone, a drop-down list will be placed in the column axis instead of the buttons. The drop-down list shows the column headers available in the pivot table. Users can dynamically switch column headers with the help of the drop-down list, and the accumulation chart will be updated accordingly.

In the below code sample, the pivot chart type is set as Pie.

tagHelper
Group.cs
<ejs-pivotview id="pivotview"  height="300"  showGroupingBar="true">
    <e-datasourceSettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <e-rows>
            <e-field name="Year"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Country"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sales Amount"></e-field>
        </e-values>
        <e-formatsettings>
            <e-field name="Amount" format="C" maximumsignificantdigits="10" minimumsignificantdigits="1" usegrouping="true"></e-field>
        </e-formatsettings>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourceSettings>
    <e-chartSettings title="Sales Analysis" load="onChartLoad" >
        <e-chartSeries type="Pie">
        </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Single Axis

By default, the pivot chart will be drawn with the value field (measure) which is set first in the report under value axis. But, user can change to specific value field using the property value in e-chartSettings tag.

tagHelper
ChartSingle.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings value="Amount" title="Sales Analysis">
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Multi Axis

User can draw the pivot chart with multiple value fields by setting the property enableMultiAxis in e-chartSettings tag as true. In the below code sample, the pivot chart will be drawn with both value fields “Sold” and “Amount” available in the e-datasourcesettings.

tagHelper
ChartMultiValue.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings enableMultiAxis="true">
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

The multi axis support is not applicable for the accumulation chart types like pie, doughnut, pyramid, and funnel.

If the user binds more value fields, the result will be multiple pivot charts, and each chart will shrink within the parent container height. To avoid this, set the enableScrollOnMultiAxis property in e-chartSettings to true. By doing so, each pivot chart will only shrink to a minimal “160px” – “180px” height showing a vertical scrollbar for a clear view.

tagHelper
ChartScrollBar.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
            <e-field name="Products" type="Count"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings enableMultiAxis="true" enableScrollOnMultiAxis="true">
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Series Customization

User can customize series of the pivot chart using e-chartSeries in e-chartSettings tag. The changes handled in the property will be reflected commonly in all chart series.

In the following sample, the pivot chart type and border has been changed for all the series.

tagHelper
ChartSeries.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings enableMultiAxis="true">
        <e-chartSeries type="Column" enableTooltip="true">
            <e-border color="#000" width="2"></e-border>
        </e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

User can also customize the pivot chart series individually using the chartSeriesCreated event, which occurs after the pivot chart series has been created. You can customize each series individually by iterating them.

In the following sample, the even series are hidden in the pivot chart.

tagHelper
ChartSeriesEvent.cs
<ejs-pivotview id="PivotView" height="300" chartSeriesCreated="chartSeriesCreated">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>

<script>
    function chartSeriesCreated(args) {
        for (var pos = 0; pos < args.series.length; pos++) {
            if (pos % 2 == 0) {
                args.series[pos].visible = false;
            }
        }
    }
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Axis Customization

User can customize axis of the pivot chart using primaryXAxis and primaryYAxis properties in e-chartSettings tag.

Axis customization is not applicable for the accumulation chart types like pie, doughnut, pyramid, and funnel.

In the following sample, title of y-axis and x-axis are customized.

tagHelper
ChartAxis.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
        <e-primaryXAxis title="X axis title"></e-primaryXAxis>
        <e-primaryYAxis title="Y axis title"></e-primaryYAxis>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Legend Customization

User can customize legend using legendSettings in ChartSettings tag. By default, legend will be visible and it can be hidden by setting the property visible in legendSettings tag as false.

The pivot chart support different types of legend shapes as follows,

  • Circle
  • Rectangle
  • VerticalLine
  • Pentagon
  • InvertedTriangle
  • SeriesType
  • Triangle
  • Diamond
  • Cross
  • HorizontalLine

Here SeriesType would act as the default shape and it can changed using the property legendShape in e-chartSeries tag.

Also user can set the position of the legend in pivot chart using the property position in legendSettings tag. The available options to set the legend position are as follows,

  • Auto: Places the legend based on area type. This is the default.
  • Top: Displays the legend at the top of the pivot chart.
  • Left: Displays the legend at the left of the pivot chart.
  • Bottom: Displays the legend at the bottom of the pivot chart.
  • Right: Displays the legend at the right of the pivot chart.
  • Custom: Displays the legend based on the given x and y values.

By default, the legend is not visible for the accumulation chart types like pie, doughnut, pyramid, and funnel.

In the following sample, the legend shape and its position can be customized.

tagHelper
Legend.cs
<ejs-pivotview id="PivotView" height="300" load="onLoad">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-displayOption view="Chart"></e-displayOption>    
</ejs-pivotview>

<script>
    var pivotObj;
    function onLoad(args) {
        pivotObj = document.getElementById("PivotView").ej2_instances[0];
        pivotObj.chartSettings = {
            legendSettings: { position: "Right" },
            chartSeries: { type: "Column", legendShape: "Pentagon" }
        };
    }
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

User Interaction

Marker and CrossHair

User can enable and customize the marker and crosshair using marker and crosshair properties in chartSettings respectively.

Also user can enable and customize the crosshair tooltip for axes using primaryXAxis and primaryYAxis.

Marker and crosshair is not applicable for the accumulation chart types like pie, doughnut, pyramid, and funnel.

tagHelper
Marker.cs
<ejs-pivotview id="PivotView" height="300" load="onLoad">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-displayOption view="Chart"></e-displayOption>    
</ejs-pivotview>

<script>
    var pivotObj;
    function onLoad(args) {
        pivotObj = document.getElementById("PivotView").ej2_instances[0];
        pivotObj.chartSettings = {
            crosshair: { enable: true },
            chartSeries: {
                type: "Line",
                marker: { fill: "#EEE", height: 10, width: 10, shape: "Pentagon", visible: true }
            },
            primaryXAxis: { crosshairTooltip: { enable: true, fill: "#ff0000" } },
            primaryYAxis: { crosshairTooltip: { enable: true, fill: "#0000FF" } }
        };
    }
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Zooming and Panning

User can customize zooming and panning option using the property e-zoomSettings in e-chartSettings tag.

The pivot chart support four types of zooming which can be set as follows,

and three modes of zooming direction that specifies whether to zoom vertically or horizontally or in both ways which are,

  • x: Pivot chart can be zoomed horizontally.
  • y: Pivot chart can be zoomed vertically.
  • x,y: Pivot chart can be zoomed both vertically and horizontally.

This can be set using the property mode in e-zoomSettings tag. By default, if the pivot chart is zoomed, a toolbar would display with the options - Zoom, ZoomIn, ZoomOut, Pan, Reset. User can also customize its option using the property toolbarItems in e-zoomSettings tag.

Zooming and panning is not applicable for the accumulation chart types like pie, doughnut, pyramid, and funnel.

tagHelper
Zooming.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
        <e-zoomSettings enableDeferredZooming="true" enableMouseWheelZooming="true" enablePinchZooming="true" enableSelectionZooming="true"></e-zoomSettings>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Tooltip

By default, tooltip for the pivot chart is enabled. User can customize it by using the property e-tooltip in e-chartSettings tag.

The tooltip can be disabled by setting the property enable in e-tooltip tag as false.

tagHelper
ChartTooltip.cs
<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
        <e-tooltip enableMarker="true" fill="#FFF" opacity="1">
            <e-tooltip-textstyle color="#000"></e-tooltip-textstyle>
            <e-tooltip-border color="#000"></e-tooltip-border>
        </e-tooltip>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Export

The pivot chart can be exported using the chartExport method which holds parameters like export type, file name, PDF orientation, width, and height in the same order. The mandatory parameters for this method are export type and file name whereas other parameters are optional.

The following are the four export types:

  • PNG
  • JPEG
  • SVG
  • PDF

In the following code sample, exporting can be done using an external button named as “Chart Export”.

tagHelper
Export.cs
<ejs-button id="chartexport" content="Export" isPrimary="true"></ejs-button>

<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>

<script>
    var pivotObj;
    document.getElementById("chartexport").onclick = function () {
        pivotObj = document.getElementById("PivotView").ej2_instances[0];
        pivotObj.chartExport("PNG", "result");
    }
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output

Print

The rendered pivot chart can be printed directly from the browser by calling printChart method.

In the following code sample, printing can be done using an external button named as “Print”.

tagHelper
Print.cs
<ejs-button id="chartprint" content="Print" isPrimary="true"></ejs-button>

<ejs-pivotview id="PivotView" height="300">
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false">
        <e-formatsettings>
            <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
        </e-formatsettings>
        <e-rows>
            <e-field name="Country"></e-field>
            <e-field name="Products"></e-field>
        </e-rows>
        <e-columns>
            <e-field name="Year" caption="Year"></e-field>
            <e-field name="Quarter"></e-field>
        </e-columns>
        <e-values>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
    </e-datasourcesettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
    </e-chartSettings>
    <e-displayOption view="Chart"></e-displayOption>
</ejs-pivotview>

<script>
    var pivotObj;
    document.getElementById("chartprint").onclick = function () {
        pivotObj = document.getElementById("PivotView").ej2_instances[0];
        pivotObj.printChart();
    }
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output