Legend

13 Jun 20238 minutes to read

The Legend contains the list of the ranges that appear in the circular gauge

Legend Visibility

By default, the legend will not be displayed in the circular gauge. You can enable or disable it by using the Visible property of the legend.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        //Visible CircularGauge legend
        .Legend(lg=>lg.Visible(true))
         //...
     )

    Click here to view the online demo sample for legend in the circular Gauge.

    Legend Text

    The text displayed in the legend can be customized by using the LegendText property present in the ranges of the circular gauge. When the legendText is not specified in the ranges, then the legend item for that particular range will not displayed. By default the legendText value is null .

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
                    .Scales(scale =>
                    {
                        scale.Ranges(range =>
                        {
                            range.LegendText("Light air").Add();
    
                        })
            
                    })
     )

    Position and Align the Legend

    By using the Position property, you can position the legend at left, right, top or bottom of the CircularGauge. The legend is positioned at the bottom of the circular gauge, by default.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg.
            //...
            //Place the legend at top of the CircularGauge        
            Position(CircularLegendPosition.Top)
        )
         //...
     )

    Legend Alignment

    You can align the legend to the center, far or near based on its position by using the Alignment property.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg.
            //...
            //The below two settings will place the legend at the top-right corner of the gauge.
            Position(CircularLegendPosition.Top)
            .Alignment(CircularLegendAlignment.Far)
        )

    Customization

    Legend Fill and Opacity

    You can change the opacity and fill color of legend text using Opacity and Fill property of legend.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
                    //...
                    //fill color of legend
                     .Fill('red')
                    //opacity of legend
                     .Opacity(0.8)
              )
         //...
     )

    Legend shape

    To change the legend item shape, you have to specify the desired shape in the Shape property of the legend. By default, the shape of the legend is circle.It also supports rectangle,diamond,triangle,slider,line,pentagon,trapezoid and wedge shapes.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
            //...
            //Change legend shape
            .Shape(CircularLegendShape.Slider)
        )
         //...
     )

    Legend Item Size and Border

    You can change the size of the legend items by using the Width and Height properties in the ItemStyle. To change the legend item border, use Border property of the legend itemStyle. The color and width of legend item border can be customized using border Color and Width property.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
            //...
            //Change legend items border, height and width
            .ItemStyle(item=>item.Width(13).Height(13).Border(br=>br.Width(2).Color("#FF0000")))
        )
         //...
     )

    Legend size

    You can change the default legend size by using the Size property of the legend. The height and width of legend size can customized using Height and Width property.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
            //...
            //Change legend size
            .Size(size=>size.Height("100").Width("350"))
        )
         //...
     )

    Legend Item Padding

    You can control the spacing between the legend items by using the ItemPadding option of the legend. The default value is 20.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
            //...
            //Add space between each legend item
            .ItemPadding(30)
        )
         //...
     )
    >

    Legend border

    You can customize the legend border by using the Border option in the legend. The legend border can be customized using border Color and Width property.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
            //...
            //Set border color and width to legend
            .Border(br=>br.Color("#FFC342").Width(2))
        )
         //...
     )

    Font of the legend text

    The Font of the legend item text can be customized by using properties such as FontFamily, FontStyle, FontWeight and Size of legend font.

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
            //...
            //Customize the legend item text
            .Font(font=>font.FontFamily("Segoe UI").FontStyle(CircularGaugeFontStyle.Normal)
                .FontWeight(CircularGaugeFontWeight.Bold).Size("15px"))
                )
         //...
     )

    Events

    Legend Item Render

    LegendItemRender event triggers before rendering the legend items. This event is triggered for each legend item in Circular gauge. You can use this event to customize legend item shape or add custom text to legend item dynamically

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
           .Visible(true)
            //...       
        )
         //Subscribe the legend item render event
         .LegendItemRender("onLegendRender")
     )
            
         function onLegendRender(sender) {
            //Get legend item details before rendering
            var legendItem = sender.data;
          }

    Legend Item Click

    You can get the legend item details such as RangeIndex, bounds and shape by subscribing the LegendItemClick event of the circular gauge. When the legend item is clicked, it triggers the event and returns the legend information

  • CSHTML
  • @(Html.EJ().CircularGauge("circulargauge1")
    
          // ...
        
        .Legend(lg=>lg
           .Visible(true)
            //...       
        )
         //Subscribe the legend item click event
         .LegendItemClick("onLegendClicked")
     )
            
         function onLegendClicked(sender) {
            //Get legend item details on legend item click.
            var legendItem = sender.data;
          }