Search results

Axis Customization in ASP.NET MVC Bullet Chart control

20 Oct 2021 / 3 minutes to read

MajorTickLines and MinorTickLines Customization

You can customize the width, color, and size of minor and major tick lines using the majorTickLines and minorTickLines properties of the bullet-chart.

The following properties can be used to customize majorTicklines and minorTicklines.

  • width - Specifies the width of ticklines.
  • height - Specifies the height of ticklines.
  • color - Specifies the color of ticklines.
  • useRangeColor - Specifies the color of ticklines and represents the color from corresponding range colors.

Customizing Major and Minor TickLines in Bullet Chart

Tick Placement

The major and the minor ticks can be placed inside or outside the ranges using the tickPosition property.

Label Format

Axis numeric labels can be formatted by using the labelFormat property. Axis labels support all globalize formats.

razor
label-format.cs
Copied to clipboard
@Html.EJS().BulletChart("container")
                        .Title("Sales Rate")
                        .Tooltip(tp => tp.Enable(true))
                        .ValueField("value")
                        .TargetField("target")
                        .Ranges(rn =>
                        {
                            rn.End(500).Add();
                            rn.End(1500).Add();
                            rn.End(2500).Add();
                        })
                        .Minimum(0).Maximum(2500).Interval(250)
                        .DataSource(ViewBag.dataSource)
                        .Render()
Copied to clipboard
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 1500, target = 1300}     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
        }

Changing Label Format in Bullet Chart

The following table describes the result of applying some commonly used formats to numeric axis labels.

Label Value Label Format property value Result Description
1000 n1 1000.0 The Number is rounded to 1 decimal place
1000 n2 1000.00 The Number is rounded to 2 decimal place
1000 n3 1000.000 The Number is rounded to 3 decimal place
0.01 p1 1.0% The Number is converted to percentage with 1 decimal place
0.01 p2 1.00% The Number is converted to percentage with 2 decimal place
0.01 p3 1.000% The Number is converted to percentage with 3 decimal place
1000 c1 * 000.0 The Currency symbol is appended to number and number is rounded to 1 decimal place
1000 c2 * 000.00 The Currency symbol is appended to number and number is rounded to 2 decimal place

GroupingSeparator

To separate groups of thousands, use the enableGroupSeparator property of bullet-chart. To separate the groups of thousands, set the enableGroupSeparator property to true.

Custom Label Format

Using the labelFormat property, axis labels can be specified with a custom defined format in addition to the axis value. The label format uses a placeholder such as ${value}K, which represents the axis label.

razor
custom-label.cs
Copied to clipboard
@Html.EJS().BulletChart("container")
                        .Title("Sales Rate")
                        .Tooltip(tp => tp.Enable(true))
                        .ValueField("value")
                        .TargetField("target")
                        .LabelFormat("${value}K")
                        .Ranges(rn =>
                        {
                            rn.End(500).Add();
                            rn.End(1500).Add();
                            rn.End(2500).Add();
                        })
                        .Minimum(0).Maximum(2500).Interval(250)
                        .DataSource(ViewBag.dataSource)
                        .Render()
Copied to clipboard
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 1500, target = 1300}     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
        }

Bullet Chart with Custom Label Format

Label Placement

You can customize the axis labels inside or outside the bullet-chart using the labelPosition property.

Opposed Position

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

Category Label

The Bullet Chart supports X-axis label by specifying the property from the data source to the categoryField. It helps to understand the input data in a more efficient way.

razor
category.cs
Copied to clipboard
@Html.EJS().BulletChart("container")
                        .Title("Sales Rate")
                        .Tooltip(tp => tp.Enable(true))
                        .ValueField("value")
                        .TargetField("target")
                        .CategoryField("category")
                        .Ranges(rn =>
                        {
                            rn.End(500).Add();
                            rn.End(1500).Add();
                            rn.End(2500).Add();
                        })
                        .Minimum(0).Maximum(2500).Interval(250)
                        .DataSource(ViewBag.dataSource)
                        .Render()
Copied to clipboard
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 1500, target = 1300, category = "Product A" }     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
            public string category;
        }

Bullet Chart with Category Label

Category Label Customization

The label color, opacity, font size, font family, font weight, and font style can be customized by using the categoryLabelStyle setting for category and the labelStyle setting for axis label. The useRangeColor property specifies the color of the axis label and represents the color from the corresponding range colors.

razor
category-label.cs
Copied to clipboard
@Html.EJS().BulletChart("container")
                        .Title("Sales Rate")
                        .Tooltip(tp => tp.Enable(true))
                        .ValueField("value")
                        .TargetField("target")
                        .CategoryField("category")
                        .Ranges(rn =>
                        {
                            rn.End(500).Add();
                            rn.End(1500).Add();
                            rn.End(2500).Add();
                        })
                        .Minimum(0).Maximum(2500).Interval(250)
                        .DataSource(ViewBag.dataSource)
                        .Render()
Copied to clipboard
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 1500, target = 1300, category = "Product A" }     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
            public string category;
        }

Customizing Axis and Category Label in Bullet Chart