Axis Customization in ASP.NET CORE Chart Component

3 Jan 202324 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-chart id="container" title="Olympic Medals">
        <e-chart-primaryxaxis valueType="Category" crossesAt="15"></e-chart-primaryxaxis>
        <e-chart-primaryyaxis crossesAt="5"></e-chart-primaryyaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource"  xName="x" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"></e-series>
        </e-series-collection>
    </ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 },
                new ColumnChartData { x= "GBR", yValue= 27 },
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

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.

@{
  var title = new {
            size= "16px", color="red",
            fontFamily="Segoe UI", fontWeight="bold"
};
}

    <ejs-chart id="container" title="Olympic Medals">
        <e-chart-primaryxaxis valueType="Category" title="Countries" titleStyle="title">
        </e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource"  xName="x" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"></e-series>
        </e-series-collection>
    </ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 },
                new ColumnChartData { x= "GBR", yValue= 27 },
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

Title Rotation

By using the titleRotation property, you can rotate the axis title from 0 to 360 degree.

@{
  var title = new {
            size= "16px", color="red",
            fontFamily="Segoe UI", fontWeight="bold"
};
}

    <ejs-chart id="container" title="Olympic Medals">
        <e-chart-primaryxaxis valueType="Category" title="Countries" titleStyle="title" titleRotation="90">
        </e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource"  xName="x" yName="yValue" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"></e-series>
        </e-series-collection>
    </ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "USA", yValue= 46 },
                new ColumnChartData { x= "GBR", yValue= 27 },
                new ColumnChartData { x= "CHN", yValue= 26 },
                new ColumnChartData { x= "UK", yValue= 26 },
                new ColumnChartData { x= "AUS", yValue= 26 },
                new ColumnChartData { x= "IND", yValue= 26 },
                new ColumnChartData { x= "DEN", yValue= 26 },
                new ColumnChartData { x= "MEX", yValue= 26 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
        }

Tick Lines Customization

You can customize the  widthcolor and size of the minor and major tick lines, using majorTickLines and minorTickLines properties in the axis.

<ejs-chart id="container" title="Sales History of Product X" >
            <e-chart-primaryxaxis valueType="Category">
   <e-majorticklines color="blue" width="2"></e-majorticklines>
</e-chart-primaryxaxis>
            <e-chart-primaryyaxis title="Profit ($)">
                <e-majorticklines color="blue" width="2"></e-majorticklines>
</e-chart-primaryyaxis>
            <e-series-collection>
                <e-series name="Product X" dataSource="ViewBag.dataSource" xName="x" yName="yValue"
                          type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"
                         ></e-series>
            </e-series-collection>
        </ejs-chart>
public IActionResult Index()
        {
              List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "John", yValue= 10000, yValue1=37, yValue2=38 },
                new ColumnChartData { x= "Jake", yValue= 12000, yValue1=23, yValue2=17 },
                new ColumnChartData { x= "Peter", yValue= 18000, yValue1=18, yValue2=26 },
                new ColumnChartData { x= "James", yValue= 11000, yValue1=18, yValue2=26 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
            public double yValue1;
            public double yValue2;
        }

Grid Lines Customization

You can customize the widthcolor and dashArray of the minor and major grid lines, using majorGridLines and minorGridLines properties in the axis.

<ejs-chart id="container" title="Sales History of Product X" >
            <e-chart-primaryxaxis valueType="Category">
   <e-majorgridlines color="blue" width="2"></e-majorgridlines>
</e-chart-primaryxaxis>
            <e-chart-primaryyaxis title="Profit ($)">
                <e-majorgridlines color="blue" width="2"></e-majorgridlines>
</e-chart-primaryyaxis>
            <e-series-collection>
                <e-series name="Product X" dataSource="ViewBag.dataSource" xName="x" yName="yValue"
                          type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"
                         ></e-series>
            </e-series-collection>
        </ejs-chart>
public IActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData { x= "John", yValue= 10000, yValue1=37, yValue2=38 },
                new ColumnChartData { x= "Jake", yValue= 12000, yValue1=23, yValue2=17 },
                new ColumnChartData { x= "Peter", yValue= 18000, yValue1=18, yValue2=26 },
                new ColumnChartData { x= "James", yValue= 11000, yValue1=18, yValue2=26 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ColumnChartData
        {
            public string x;
            public double yValue;
            public double yValue1;
            public double yValue2;
        }

Multiple Axis

In addition to primary X and Y axis, add n number of axis to the chart. Series can be associated with this axis, by mapping with axis’s unique name.

<ejs-chart id="container" title="Olympic Medals">
        <e-chart-primaryxaxis valueType="Category">
        </e-chart-primaryxaxis>
       <e-chart-axes>
           <e-chart-axis rowIndex="0" name="yAxis"></e-chart-axis>
       </e-chart-axes>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"></e-series>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y1" yAxisName="yAxis" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line"></e-series>
        </e-series-collection>
    </ejs-chart>
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-chart id="container" title="Olympic Medals">
        <e-chart-primaryxaxis valueType="Category">
        </e-chart-primaryxaxis>
        <e-chart-primaryyaxis isInversed="true">
        </e-chart-primaryyaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"></e-series>
        </e-series-collection>
    </ejs-chart>
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;
        }

Opposed Position

To place an axis opposite from its original position, set opposedPosition property of the axis to true.

<ejs-chart id="container" title="Olympic Medals">
        <e-chart-primaryxaxis valueType="Category">
        </e-chart-primaryxaxis>
        <e-chart-primaryyaxis opposedPosition="true">
        </e-chart-primaryyaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column"></e-series>
        </e-series-collection>
    </ejs-chart>
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;
        }