Legend

Legend visibility

You can enable or disable the legend by using the visible property in the legend object.

NOTE

By default, the legend is visible in the pivot chart.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
    		legend: { 
    			visible: true 
    		},
    	});
    });

    Legend shape

    You can customize the legend shape in the pivot chart control. The default value of legend shape is rectangle. Following are the legend shapes that are supported:

    • Rectangle
    • Circle
    • Cross
    • Diamond
    • Pentagon
    • Hexagon
    • Star
    • Ellipse
    • Triangle etc.
  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
    		legend: {
                visible: true,
                shape: "star"
            },
    	});
    });

    Legend position

    By using the position property, you can place the legend at top, bottom, left, or right of the pivot chart.

    NOTE

    The default value of legend position is bottom in the pivot chart.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
            legend: {
                visible: true,
                position: "top"
            },
    	});
    });

    Legend title

    To add the legend title, you should specify the title text in the title.text property.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
            legend: {
                visible: true,
                title: {
                    text : "Countries"
                }
            },
    	});
    });

    Legend alignment

    You can align the legend to center, far, and near based on its position in the chart area by using the alignment option.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
            legend: {
                visible: true,
                alignment: "near"
            },
    	});
    });

    Legend items - size and border

    By using the legend itemStyle.width, itemStyle.height, and itemStyle.border properties, you can change the size and border of legend items.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
            legend: {
                visible: true,
                itemStyle: {
                    border: {
                        width: 1.5,
                        color: "magenta"
                    },
                    width: 12,
                    height: 12
                }
            },
    	});
    });

    Legend border

    By using the border option in the legend, you can customize the border color and width.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
            legend: {
                visible: true,
                border: {
                    color: "orange",
                    width: 5
                }
            },
    	});
    });

    Legend text

    By using the font option, you can customize the font family, font style, font weight, and size of the legend text.

  • html
  • /// <reference path="jquery.d.ts" />
    /// <reference path="ej.web.all.d.ts" />
    
    $(function () {
        var sample = new ej.PivotChart($("#PivotChart1"), { 
            legend: {
                visible: true,
                font: {
                    size: "20px",
                    color: "blue",
                    fontWeight: "bold",
                    fontFamily: "Segoe UI"
                }
            },
    	});
    });