JavaScript/jQuery Chart - Arrange Axis Ticks

On a Continuous Axis

A continuous axis indicates numeric or date-time values. If you know the range of these values, you can arrange ticks using the tickInterval property. It specifies the interval between two side-by-side major ticks. For numeric values, this property accepts a number; for date-time values, it accepts a string or an object with a single field that designates the date component measuring the interval. Similarly, you can arrange minor ticks using the minorTickInterval property.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • // ...
  • argumentAxis: { // or valueAxis
  • tickInterval: 10,
  • minorTickInterval: 2,
  •  
  • // === or ===
  • tickInterval: { years: 1 },
  • minorTickInterval: { months: 6 },
  •  
  • // === or ===
  • tickInterval: 'year',
  • minorTickInterval: 'month',
  •  
  • // Making ticks visible
  • tick: { visible: true },
  • minorTick: { visible: true }
  • }
  • });
  • });

Without knowing the range of values on the axis, you can arrange major ticks by specifying the minimum distance between two side-by-side ticks in pixels. For this purpose, set the axisDivisionFactor property. Minor ticks in this case should be arranged using the minorTickCount property. It specifies how many minor ticks to place between two side-by-side major ticks.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • // ...
  • argumentAxis: { // or valueAxis
  • axisDivisionFactor: 20,
  • minorTickCount: 4,
  •  
  • tick: { visible: true },
  • minorTick: { visible: true }
  • }
  • });
  • });

On a Discrete Axis

Values on a discrete axis are called "categories", and ticks on this axis separate one category from another. In terms of tick arrangement, you can only specify whether ticks (and consequently, grid lines) should be placed between axis labels or should cross them. Use the discreteAxisDivisionMode property for this purpose.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • // ...
  • argumentAxis: { // or valueAxis
  • tick: { visible: true },
  • discreteAxisDivisionMode: 'crossLabels' // or 'betweenLabels'
  • }
  • });
  • });

On a Logarithmic Axis

A logarithmic axis indicates numeric values; each of them is the logarithmBase value raised to some power. For example, logarithmBase that is equal to 10 produces the following values: 10-2, 10-1, 100, 101, 102, 103, etc. That is so if the tickInterval property is 1. Changing tickInterval, for example, to 2 removes every second value from this sequence, leaving the following: 10-1, 101, 103, etc.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • // ...
  • argumentAxis: { // or valueAxis
  • type: 'logarithmic'
  • tickInterval: 2,
  • tick: { visible: true }
  • }
  • });
  • });

As an alternative to tickInterval, you can use the axisDivisionFactor property to arrange ticks. This property specifies the minimum distance between two side-by-side ticks in pixels.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • // ...
  • argumentAxis: { // or valueAxis
  • type: 'logarithmic'
  • axisDivisionFactor: 20,
  • tick: { visible: true }
  • }
  • });
  • });
See Also