Axis customization in EJ2 JavaScript Bullet chart control
8 May 202324 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.
var chart = new ej.charts.BulletChart({
majorTickLines: { color: 'blue', width: 5 },
minorTickLines: {width: 4, color: 'red'},
dataSource: [{ value: 23, target: 22 }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 20 },
{ end: 25 },
{ end: 30 }
],
minimum: 0, maximum: 30, interval: 5
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>Tick Placement
You can place major and minor ticks inside or outside the ranges using the tickPosition property of bullet-chart. The major and the minor ticks can be placed inside or outside the ranges using the tickPosition property.
var chart = new ej.charts.BulletChart({
tickPosition: 'Inside',
dataSource: [{ value: 23, target: 22 }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 20 },
{ end: 25 },
{ end: 30 }
],
minimum: 0, maximum: 30, interval: 5,
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>Label Format
Axis Label Format
Axis numeric labels can be formatted by using the labelFormatproperty. Axis labels support all globalize formats. The following table describes the result of applying some commonly used label formats on numeric axis values.
Axis numeric labels can be formatted by using the labelFormat property. Axis labels support all globalize formats.
var chart = new ej.charts.BulletChart({
labelFormat: 'c',
dataSource: [{ value: 23, target: 22 }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 20 },
{ end: 25 },
{ end: 30 }
],
minimum: 0, maximum: 30, interval: 5,
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>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 | $1000.0 | The Currency symbol is appended to number and number is rounded to 1 decimal place |
| 1000 | c2 | $1000.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.
var chart = new ej.charts.BulletChart({
enableGroupSeparator: true,
title: 'Sales Rate',
dataSource: [{ value: 1500, target: 1300 }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 500 },
{ end: 1500 },
{ end: 2500 }
],
minimum: 0, maximum: 2500, interval: 250
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>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.
var chart = new ej.charts.BulletChart({
labelFormat: '${value}K',
title: 'Sales Rate',
dataSource: [{ value: 1500, target: 1300, category: 'Product A' }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 500 },
{ end: 1500 },
{ end: 2500 }
],
minimum: 0, maximum: 2500, interval: 250
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>Label Placement
You can customize the axis labels inside or outside the bullet-chart using the labelPosition property. Label can be placed Inside or Outside of the ranges using the labelPosition property.
var chart = new ej.charts.BulletChart({
labelPosition: 'Inside',
dataSource: [{ value: 23, target: 22 }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 20 },
{ end: 25 },
{ end: 30 }
],
minimum: 0, maximum: 30, interval: 5,
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>Opposed Position
To place an axis opposite to its original position, set the opposedPosition property to true. To place an axis opposite to its original position, set the opposedPosition] property to true.
var chart = new ej.charts.BulletChart({
majorTickLines: { color: 'blue', width: 5 },
minorTickLines: {width: 4, color: 'red'},
dataSource: [{ value: 23, target: 22 }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
ranges: [{ end: 20 },
{ end: 25 },
{ end: 30 }
],
minimum: 0, maximum: 30, interval: 5
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>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.
var chart = new ej.charts.BulletChart({
title: 'Sales Rate',
dataSource: [{ value: 1500, target: 1300, category: 'Product A' }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
categoryField: 'category',
ranges: [{ end: 500 },
{ end: 1500 },
{ end: 2500 }
],
minimum: 0, maximum: 2500, interval: 250
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>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.
var chart = new ej.charts.BulletChart({
title: 'Sales Rate',
dataSource: [{ value: 1500, target: 1300, category: 'Product A' }],
animation: { enable: false },
valueField: 'value',
targetField: 'target',
categoryField: 'category',
categoryLabelStyle: { color: 'Orange'},
ranges: [{ end: 500 },
{ end: 1500 },
{ end: 2500 }
],
minimum: 0, maximum: 2500, interval: 250
}, '#element');<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>