Legend
17 Feb 202213 minutes to read
Legend provides information about the series rendered in the Stock Chart. Legend can be added to a Stock Chart by enabling the Visible
option in the LegendSettings
.
Position and Alignment
By using the Position
property, legend can be placed at Left
, Right
, Top
, Bottom
or Custom
of the Stock Chart. The legend is positioned at the bottom of the Stock Chart, by default.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true).Position("Top"))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Custom
position is used to position the legend anywhere in the Stock Chart using x, y coordinates.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true).Position("Custom").location(location => location.x(200).y(20)))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Legend Alignment
The legend can be align as Center
, Far
or Near
to the Stock Chart using Alignment
property.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true).Position("Bottom").Alignment("Near"))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Customization
To change the legend icon shape, LegendShape
property in the Series
can be used. By default legend icon shape is SeriesType
.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").legendShape("Pentagon").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Legend Size
By default, legend takes 20% - 25% of the Stock Chart’s height horizontally, when it is placed on top or bottom position and 20% - 25% of the width vertically, while placing on left or right position of the Stock Chart. The default legend size can be changed by using the Width
and Height
property of the LegendSettings
.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true).width(500).height(50).border(border => border.width(1).color("pink")))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Legend Item Size
The size of the legend items can customized by using the ShapeHeight
and ShapeWidth
property.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true).shapeHeight(15).shapeWidth(15))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Collapsing Legend Item
By default, series name will be displayed as legend. To skip the legend for a particular series, empty string to the series name can be given.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}
Legend Title
The title for legend can be set using Title
property in LegendSettings
. Customize the FontStyle
, Size
, FontWeight
, Color
, TextAlignment
, FontFamily
, Opacity
and TextOverflow
of legend title. TitlePosition
is used to set the legend position in Top
, Left
and Right
position. MaximumTitleWidth
is used to set the width of the legend title. By default, it will be 100px
.
<script src="~/datasource.js"></script>
@(Html.EJS().StockChart("container").Load("load").Title("Unemployment Rates 1975-2010")
.PrimaryXAxis(xaxis => xaxis.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime))
.Series(sr =>
{
sr.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Candle).DataSource("data").Name("China").Add();
})
.Tooltip(tooltip => tooltip.Enable(true))
.LegendSettings(legend => legend.Visible(true).title("Countries").titlePosition("Top"))
.Render())
<script>
var data = window.chartData;
var load = function (args) {
args.stockChart.indicatorType = [];
args.stockChart.trendlineType = [];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers.StockChart
{
public partial class StockChartController : Controller
{
public IActionResult Default()
{
return View();
}
}
}