Search results

Tooltip in ASP.NET Core Pivot Table control

The tooltip can be enabled or disabled by setting the showTooltip property to true. By default, tooltip is enabled in the pivot table.

tagHelper
ToolTip.cs
<ejs-pivotview id="PivotView" height="300" showTooltip="false">
    <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>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

Tooltip Template

User can design their own tooltip by setting the property tooltipTemplate with own HTML elements. The property accepts both HTML string and ID attribute. The following place holders are available to display its dynamic values inside the HTML elements.

${rowHeaders} – Row headers of the selected value cell.

${columnHeaders} – Column headers of the selected value cell.

${rowFields} – Row fields of the selected value cell.

${columnFields} – Column fields of the selected value cell.

${valueField} – Field name of the selected value cell.

${aggregateType} – Aggregate type of the selected value cell.

${value} - Formatted value of the selected value cell.

The tooltip customization is common for both pivot table and pivot chart or it can be done individually as well. To customize the pivot table tooltip, the above procedure needs to be followed. To customize the pivot chart tooltip alone use template property of tooltip under e-chartSettings.

In the below sample, the pivot table and pivot chart shows customized tooltip layouts.

tagHelper
tooltip-template.cs
<ejs-pivotview id="pivotview" showToolbar="true" tooltipTemplate="#Template" width="100%" height="300" toolbar="@(new List<string>() {"Grid", "Chart" })" >
    <e-datasourcesettings dataSource="@ViewBag.DataSource" expandAll="false" enableSorting="true">
        <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"></e-field>
            <e-field name="Order_Source" caption="Order Source"></e-field>
        </e-columns>
        <e-values>
            <e-field name="In_Stock" caption="In Stock"></e-field>
            <e-field name="Sold" caption="Units Sold"></e-field>
            <e-field name="Amount" caption="Sold Amount"></e-field>
        </e-values>
        <e-filters>
            <e-field name="Product_Categories" caption="Product Categories"></e-field>
        </e-filters>
    </e-datasourcesettings>
    <e-gridSettings columnWidth="140"></e-gridSettings>
    <e-chartSettings>
        <e-chartSeries type="Column"></e-chartSeries>
        <e-tooltip enableMarker="true" template="<span class='wrap'>${aggregateType} of ${valueField}: ${value}</span>">
        </e-tooltip>
    </e-chartSettings>
    <e-displayOption view="Both"></e-displayOption>
</ejs-pivotview>
<style>
    #pivotview {
        width: 100%;
        height: 100%;
    }

    .e-tool-expand::before {
        content: '\e702';
    }

    .wrap {
        border: 3px solid #27b1f0;
        background-color: #4d4d4d;
        width: auto;
        color: #FFFFFF;
        padding: 5px;
        font-size: 12px;
    }

    .pivotTooltipValue {
        font-style: italic;
    }

    .pivotTooltipHeader {
        color: aqua;
        font-weight: bold;
        width: 100px;
    }
</style>
<script id="Template" type="text/x-template">
        <div class='wrap'>
                    <div>
                        <span class='pivotTooltipHeader'>Row Headers :</span > 
                        <span class='pivotTooltipValue'>${columnHeaders}${rowHeaders}</span >
                    </div>
                    <div>
                        <span class='pivotTooltipHeader'>Row Fields : </span>
                        <span class='pivotTooltipValue'>${rowFields}</span>
                    </div>
                    <div>
                        <span class='pivotTooltipHeader'>Column Headers :</span >
                        <span class='pivotTooltipValue'>${columnHeaders}</span>
                    </div>
                    <div>
                        <span class='pivotTooltipHeader'>Column Fields :</span> 
                        <span class='pivotTooltipValue'>${columnFields}</span>
                    </div>
                    <div>
                        <span class='pivotTooltipHeader'>Value Field :</span> 
                        <span class='pivotTooltipValue'>${valueField}</span>
                    </div>
                    <div>
                        <span class='pivotTooltipHeader'>Value : </span>
                        <span class='pivotTooltipValue'>${value}</span>
                    </div>
        </div>
</script>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.DataSource = data;
    return View();
}

output


output