Articles in this section

How to render a legend without pagination in Blazor Charts?

This article explains how to render a legend without pagination in Blazor Charts.

Render a Legend Without Pagination

Blazor Charts offers the option to render a legend without pagination. To achieve this, you need to increase the legend Height to prevent paging.

In this code snippet, a multi-line chart is created to analyze stock prices over time. The chart features multiple ChartSeries elements to display different stock price data for various products. Each series is plotted using a line chart, with markers enabled for clarity. The ChartLegendSettings Height is set to 40% to ensure that all legend entries are visible without pagination. The data for the chart is generated dynamically, with stock prices fluctuating randomly over a specified period.

@using Syncfusion.Blazor.Charts

<SfChart Width="50%" Title="Stock Price Analysis">
   <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime" />
   <ChartPrimaryYAxis Title="Price" LabelFormat="${value}" />
   <ChartSeriesCollection>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice1" Width="2" Name="Product A">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice2" Width="2" Name="Product B">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice3" Width="2" Name="Product C">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice4" Width="2" Name="Product D">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice5" Width="2" Name="Product E">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice6" Width="2" Name="Product F">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice7" Width="2" Name="Product G">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice8" Width="2" Name="Product H">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice9" Width="2" Name="Product I">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
       <ChartSeries Type="ChartSeriesType.Line" DataSource="@ChartPoints" XName="Period" YName="StockPrice10" Width="2" Name="Product J">
           <ChartMarker Visible="true"></ChartMarker>
       </ChartSeries>
   </ChartSeriesCollection>
   <ChartLegendSettings Height="40%" />
</SfChart>

@code {
   private Random randomNum = new Random();
   private double stockPrice1 = 10, stockPrice2 = 20, stockPrice3 = 30, stockPrice4 = 40, stockPrice5 = 50, stockPrice6 = 60,
   stockPrice7 = 70, stockPrice8 = 80, stockPrice9 = 90, stockPrice10 = 100;
   public List<LineChartData> ChartPoints { get; set; } = new List<LineChartData>();

   protected override void OnInitialized()
   {
       GetChartPoints();
   }

   private void GetChartPoints()
   {
       for (int i = 1; i < 10; i++)
       {
           if (randomNum.NextDouble() > 0.5)
           {
               stockPrice1 += randomNum.NextDouble();
               stockPrice2 += randomNum.NextDouble();
               stockPrice3 += randomNum.NextDouble();
               stockPrice4 += randomNum.NextDouble();
               stockPrice5 += randomNum.NextDouble();
               stockPrice6 += randomNum.NextDouble();
               stockPrice7 += randomNum.NextDouble();
               stockPrice8 += randomNum.NextDouble();
               stockPrice9 += randomNum.NextDouble();
               stockPrice10 += randomNum.NextDouble();
           }
           else
           {
               stockPrice1 -= randomNum.NextDouble();
               stockPrice2 -= randomNum.NextDouble();
               stockPrice3 -= randomNum.NextDouble();
               stockPrice4 -= randomNum.NextDouble();
               stockPrice5 -= randomNum.NextDouble();
               stockPrice6 -= randomNum.NextDouble();
               stockPrice7 -= randomNum.NextDouble();
               stockPrice8 -= randomNum.NextDouble();
               stockPrice9 -= randomNum.NextDouble();
               stockPrice10 -= randomNum.NextDouble();
           }
           ChartPoints.Add(new LineChartData
               {
                   Period = new DateTime(1960, 1, 1).AddMonths(i + 1).AddDays(i),
                   StockPrice1 = Math.Round(stockPrice1),
                   StockPrice2 = Math.Round(stockPrice2),
                   StockPrice3 = Math.Round(stockPrice3),
                   StockPrice4 = Math.Round(stockPrice4),
                   StockPrice5 = Math.Round(stockPrice5),
                   StockPrice6 = Math.Round(stockPrice6),
                   StockPrice7 = Math.Round(stockPrice7),
                   StockPrice8 = Math.Round(stockPrice8),
                   StockPrice9 = Math.Round(stockPrice9),
                   StockPrice10 = Math.Round(stockPrice10),
               });
       }
   }

   public class LineChartData
   {
       public DateTime Period { get; set; }
       public double StockPrice1 { get; set; }
       public double StockPrice2 { get; set; }
       public double StockPrice3 { get; set; }
       public double StockPrice4 { get; set; }
       public double StockPrice5 { get; set; }
       public double StockPrice6 { get; set; }
       public double StockPrice7 { get; set; }
       public double StockPrice8 { get; set; }
       public double StockPrice9 { get; set; }
       public double StockPrice10 { get; set; }
   }
} 

The following screenshot illustrates the output of the code snippet.

image.png

Live Sample for Rendering a Legend Without Pagination

Conclusion

I hope you enjoyed learning how to render a legend without pagination in Blazor Charts.

You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied