Legend is a chart element which displays a list of colors, symbols and text corresponding to each data series drawn on that chart. It helps in understanding and analysis of the plotted data in the case of multiple series.
In FlexChart, a legend is automatically displayed if the Name property of the series is set. In other words, the Name property of series is required to generate a legend entry corresponding to the same. Also, FlexChart automatically places the legend according to the space available on the chart area. However, you can also set it to display in top, bottom, left or right with respect to the plot area by setting the Position property. To use the available space in the most optimized manner, FlexChart displays the legend horizontally when placed in top or bottom and vertically when placed in left or right of the plot area. At the same time, FlexChart also allows you to set the Orientation as per requirement.
With FlexChart, user can even toggle the visibility of a data series by clicking on corresponding legend entry at run-time, if the LegendToggle property of FlexChart class is set to True.
There are times when there is not enough space to display the complete text of legend entries in the chart area. FlexChart provides the TextWrapping property of Legend class that allows you to wrap or trim the text when width of text exceeds the value specified in the ItemMaxWidth property. The TextWrapping property accepts values from TextWrapping enumeration.
TextWrapping = TextWrapping.Wrap |
TextWrapping = TextWrapping.Truncate |
---|---|
![]() |
![]() |
FlexChart also allows you to style the legend and legend entries using the Style property of Legend class. This property lets you specify the fill, fill color, stroke width, stroke color etc. of the legend.
Legend grouping refers to categorization of legend entries according to the data presented by them. This feature is usually helpful in identifying the categories of data series in the case of multiple stacked series. For instance, while plotting sales and profit of multiple quarters in the same chart area, legend groups prove helpful in identifying which series are the sales series and which ones are the profit series.
To create legend groups using FlexChart, the control provides the LegendGroup property which accepts a string value and groups the series with same value together. Value of this property not only acts as the group name but the group title as well which gets displayed on the top of the corresponding legend group. The series for which the LegendGroup property is not specified is treated as a part of 0th group and is displayed without any group title. FlexChart also lets you customize the legend group titles by using the GroupHeaderStyle property of Legend class.
The Legend Ranges enables you to categorize continuous data into specific ranges, making it easier to display and understand complex data.
For example, when displaying temperature data across various states, you can group temperatures into ranges and show these groups in the legend. This helps to identify the range of a data point easily, and customizing the range's appearance improves the chart's clarity and look.
In this example, the chart visualizes the highest temperatures recorded across various US states, with each temperature range being color-coded for clarity. The legend groups the temperatures into ranges like "95 to 100", "100 to 105", and so on. Each range in the legend is assigned a distinct color, which corresponds to the colors used for the data points on the chart.
The SetupChart() method customizes the chart's appearance and implements the Legend Ranges feature by grouping temperature data into 5-degree intervals. The chart header, tooltip, axis format, and legend are configured using properties like flexChart1.Header.Content, flexChart1.ToolTip.Content, and flexChart1.AxisY.Format. The data is sourced from DataService.GetUSStatesTemperature(), with ChartType.Scatter used for visualization. A series is created using the SeriesWithPointLegendItems class, which defines custom legend items. The Ser_SymbolRendering method applies gradient colors to data points based on their values, using a formula to determine the appropriate range and selecting the corresponding color from the GradientRedColors array.
Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.
The SeriesWithPointLegendItems class implements the ISeries interface to manage the legend’s behavior by dynamically generating legend item names and defining their styles. The GetLegendItemLength method specifies the number of legend items, while GetLegendItemName dynamically creates the names for each range by calculating the lower and upper bounds. The GetLegendItemStyle method customizes the legend item’s appearance by assigning colors from the gradient collection, ensuring that the legend accurately reflects the grouped data ranges.
Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.