Axis Customization
28 Feb 202217 minutes to read
Axis Crossing
An axis can be positioned in the chart area using crossesAt and crossesInAxis properties. The crossesAt property specifies the values (datetime, numeric, or logarithmic) at which the axis line has to be intersected with the vertical axis or vice-versa, and the CrossesInAxis property specifies the axis name with which the axis line has to be crossed.
<ejs-stockchart id="stockchart" load="stockload">
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-primaryxaxis crossesAt="160"></e-stockchart-primaryxaxis>
</ejs-stockchart>
<script src="~/financial-data.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();
}
}
}
Title
You can add a title to the axis using title
property to provide quick information to the user about the data plotted in the axis.Title style can be customized using titleStyle
property of the axis.
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
</e-stockchart-series-collection>
</ejs-stockchart>
<script src="~/financial-data.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();
}
}
}
Tick Lines Customization
You can customize the width
, color
and size
of the minor and major tick lines, using majorTickLines
and minorTickLines
properties in the axis.
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-primaryxaxis>
<e-majorticklines color="blue" width="5"></e-majorticklines>
<e-minorticklines color="red" width="0"></e-minorticklines>
</e-stockchart-primaryxaxis>
<e-stockchart-primaryyaxis>
<e-majorticklines color="green" width="5"></e-majorticklines>
<e-minorticklines color="red" width="0"></e-minorticklines>
</e-stockchart-primaryyaxis>
</ejs-stockchart>
<script src="~/financial-data.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();
}
}
}
Grid Lines Customization
You can customize the width
, color
and dashArray
of the minor and major grid lines, using majorGridLines
and minorGridLines
properties in the axis.
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-primaryxaxis>
<e-majorgridlines color="blue" width="1"></e-majorgridlines>
<e-minorgridlines color="red" width="0"></e-minorgridlines>
</e-stockchart-primaryxaxis>
<e-stockchart-primaryyaxis>
<e-majorgridlines color="green" width="1"></e-majorgridlines>
<e-minorgridlines color="red" width="0"></e-minorgridlines>
</e-stockchart-primaryyaxis>
</ejs-stockchart>
</div>
<script src="~/financial-data.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();
}
}
}
Multiple Axis
In addition to primary X and Y axis, we can add n number of axis to the chart. Series can be associated with this axis
, by mapping with axis’s unique name.
<ejs-stockchart id="stockchart" load="chartLoad" title="Multiple Series">
<e-chart-axes>
<e-chart-axis rowIndex="0" name="yAxis"></e-chart-axis>
</e-chart-axes>
<e-stockchart-series-collection>
<e-stockchart-series type='Column' xName='x' yName='close' name='Apple' >
</e-stockchart-series>
<e-stockchart-series type='Line' xName='x' yName='close' yAxisName='yAxis' name='Google' ></e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-primaryxaxis valueType="DateTime">
<e-majorgridlines width="0"></e-majorgridlines>
</e-stockchart-primaryxaxis>
</ejs-stockchart>
<script src="~/goog.js"></script>
<script src="~/googl.js"></script>
<script>
var data1 = goog;
var data2 = googl;
function chartLoad(args) {
args.stockChart.series[0].dataSource = data1;
args.stockChart.series[1].dataSource = data2;
}
</script>
public ActionResult Index()
{
List<MultipleAxesChartData> chartData = new List<MultipleAxesChartData>
{
new MultipleAxesChartData { x = "Sun", y = 35, y1 = 30 },
new MultipleAxesChartData { x = "Mon", y = 40, y1 = 28 },
new MultipleAxesChartData { x = "Tue", y = 80, y1 = 29 },
new MultipleAxesChartData { x = "Wed", y = 70, y1 = 30 },
new MultipleAxesChartData { x = "Thu", y = 65, y1 = 33 },
new MultipleAxesChartData { x = "Fri", y = 55, y1 = 32 },
new MultipleAxesChartData { x = "Sat", y = 50, y1 = 34 }
};
ViewBag.dataSource = chartData;
return View();
}
public class MultipleAxesChartData
{
public string x;
public double y;
public double y1;
}
Inversed Axis
When an axis is inversed, highest value of the axis comes closer to origin and vice versa. To place an axis in inversed manner set this property isInversed
to true.
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-primaryxaxis isInversed="true">
</e-stockchart-primaryxaxis>
<e-stockchart-primaryyaxis isInversed="true">
</e-stockchart-primaryyaxis>
</ejs-stockchart>
<script src="~/scripts/chart/financial-data.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();
}
}
}
Opposed Position
To place an axis opposite from its original position, set opposedPosition
property of the axis to true.
<ejs-stockchart id="stockchart" load="stockload" title="AAPL Stock Price">
<e-stockchart-series-collection>
<e-stockchart-series type='Candle' xName="x"> </e-stockchart-series>
</e-stockchart-series-collection>
<e-stockchart-primaryxaxis opposedPosition="true">
</e-stockchart-primaryxaxis>
</ejs-stockchart>
<script src="~/scripts/chart/financial-data.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();
}
}
}