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.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name='China'>
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true" position="Top"></e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name='China'>
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true" position="Custom">
<e-stockchartlegendsettings-location x="200" y="20"></e-stockchartlegendsettings-location>
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name='China'>
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true" position="Bottom" alignment="Near">
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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
.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name='China' legendShape="Pentagon">
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true">
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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
.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name='China'>
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true" width="500" height="50">
<e-stockchartlegendsettings-border width="1" color="pink"></e-stockchartlegendsettings-border>
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name='China'>
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true" shapeHeight="15" shapeWidth="15">
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle'>
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true">
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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
.
<ejs-stockchart id="stockchart" load="chartLoad" indicatorType="new string[0]" trendlineType="new string[0]" title="Unemployment Rates 1975-2010">
<e-stockchart-primaryxaxis valueType="DateTime">
</e-stockchart-primaryxaxis>
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' name="China">
</e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-tooltipsettings enable="true"></e-stockchart-tooltipsettings>
<e-stockchart-legendsettings visible="true" title="Countries" titlePosition="Top" maximumTitleWidth="150">
<e-stockchartlegendsettings-titlestyle fontFamily="verdana" fontStyle="Normal" fontWeight="Normal"
size="15px" textAlignment="Center" color="blue" textOverflow="None"></e-stockchartlegendsettings-titlestyle>
</e-stockchart-legendsettings>
</ejs-stockchart>
<script src="~/datasource.js"></script>
<script>
var data = chartData;
function stockload(args) {
args.stockChart.series[0].dataSource = data;
}
</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();
}
}
}