Customizing the X axis

Using a variety of different tools and configurations, you can fully customize rendering of the X-axis.

First, review the complete list of available parameters to see if you can accomplish your desired customization by adjusting a flag. A complete list can be found at CIQ.ChartEngine.XAxis

Colors and fonts

These can be controlled by manipulating the CSS styles associated with the x-axis.

You can override the stx_xaxis class in stx-chart.css to change the font and the color. Remember that if you are using the default dark theme you will need to override the defaults for .ciq-night .stx_xaxis style.

Fully customized X-Axis

Option 1:

Set CIQ.ChartEngine.XAxis#formatter to a function which will override the x-axis labels to anything you want.

Option 2:

Use the locale/internationalizer to format dates.


CIQ.I18N.setLocale(stxx, "en"); // set localization services -- before any UI or chart initialization is done
// override date formatting of the introday hover label to add year
stxx.internationalizer.monthDay=new Intl.DateTimeFormat(this.locale, {year:"numeric", month:"numeric", day:"numeric"});

// override time formatting on both the hover and the x axis s labels to enable 12 hour clock (hour12:true)
stxx.internationalizer.hourMinute=new Intl.DateTimeFormat(this.locale, {hour:"numeric", minute:"numeric", hour12:true});
stxx.internationalizer.hourMinuteSecond=new Intl.DateTimeFormat(this.locale, {hour:"numeric", minute:"numeric", second:"numeric", hour12:true});

// override time formatting to enable 12 hour clock (hour12:true)
stxx.internationalizer.hourMinute=new Intl.DateTimeFormat(this.locale, {hour:"numeric", minute:"numeric", hour12:true});
stxx.internationalizer.hourMinuteSecond=new Intl.DateTimeFormat(this.locale, {hour:"numeric", minute:"numeric", second:"numeric", hour12:true});

More details on localization can be found in the Localization tutorial.

Option 3:

Use an API injection on createXAxis() to totally override all of the default functionality. This is an advanced feature and only recommended for someone very experienced with the library.

    // add your logic to create your own X-Axis. We can help...
     //return axisRepresentation; // This is your array of CIQ.ChartEngine.XAxisLabel() elements used by CIQ.ChartEngine.drawXAxis()

See CIQ.ChartEngine.AdvancedInjectable#createXAxis for function signature and other details.

The injection should return an axisRepresentation array (normally created internally by createXAxis() ). drawXAxis() uses this array to draw the axis. Your injection can put anything you want to see in the x-axis labels (text). Each entry should specify the type of label (boundary or line) and the pixel location where you want to set it (hz). This is done by pushing CIQ.ChartEngine.XAxisLabel() elements into the axisRepresentation array.

See CIQ.ChartEngine.XAxisLabel for additional details on format and requirements.

For instance, call either:

axisRepresentation.push(new CIQ.ChartEngine.XAxisLabel(hz,"boundary",text));


axisRepresentation.push(new CIQ.ChartEngine.XAxisLabel(hz,"line",text));

Here is a sample of what the resulting axisRepresentation array will look like. Notice there are both "line" and "boundary" type labels, and only bars needing a label will be present in the array :


Your injection will also need to create the chart.xaxis array which is used by the HUD and cross-hair labels as you slide the mouse through the chart.

This array takes objects of the following format:

var obj={
    DT: dataSegment[i].DT,    // bar date
    data: dataSegment[i]    // bar data

and should contain an entry for every bar in the current dataSegment as well as any data you wish to display in the areas where the is no chart data.

The following image shows an area where there is no data. On those, you can just send the DT field so at least a date can be shown, and the data portion can just be 'null':

No data on x axis

You can add each item like so:


Here is a subset sample of what the resulting xaxis array will look like (showing first 3 elements with data and last few elements where there is no data):


Option 4:

Allow the default axisRepresentation array to be created, but intercept it and adjust it before it is used. For this you can use an API injection similar to this:

        axisRepresentation = this.createTickXAxisWithDates(chart);
        // add you logic here to adjust the default axisRepresentation array as needed
        // iterate through each element and adjust labels(text) or horizontal location (hz)
        return axisRepresentation;
Equidistant grid - injection sample:

Here is a fully functional example of an injection that removes the boundary lines, which depending on periodicity can produce an uneven grid. It then prints the boundary labels as regular labels where it makes sense to do so. The result is a more equidistant grid, at the expense of not always seeing the boundary lines.

stxx.chart.yAxis.goldenRatioYAxis=false; // don't try to match the x grid line spacing with the y gridline spacing.
stxx.chart.xAxis.idealTickSizePixels=100; // try to put labels every 100 pixels as long as they do not overlap. Adjust as needed
stxx.chart.xAxis.minimumLabelWidth=100; // try to put labels every 100 pixels as long as they do not overlap. Adjust as needed
stxx.chart.xAxis.timeUnitMultiplier=1; // try to put labels every 1 unit as long as they do not overlap

CIQ.ChartEngine.prototype.prepend("createXAxis", function(chart){
 var axisRepresentation = this.createTickXAxisWithDates(chart);
 var i = axisRepresentation.length
 while (i--) {
     if (axisRepresentation[i].grid == "boundary") { 
       if( axisRepresentation[i+1]) axisRepresentation[i+1].text=axisRepresentation[i].text;
       axisRepresentation.splice(i, 1);

 // for 4+ hour periodicity (in this case interval larger than 240 minutes) force a time unit of HOUR instead of the DAY default
 if( this.layout.periodicity == 1 && this.layout.interval >= 240 && this.layout.timeUnit == 'minute' )
 // for seconds or tick use MILLISECOND to sure even grids even If there are multiple bards on the same secnd.
 else if( this.layout.timeUnit == 'second'|| this.layout.interval == 'tick' )
 // for weeks or tick use DAY to sure even grids.
 else if( this.layout.interval == 'week' )
 return axisRepresentation;

More granular x-axis

CIQ.ChartEngine#createTickXAxisWithDates is the method called by CIQ.ChartEngine.AdvancedInjectable#createXAxis to generate the axisRepresentation object. It is algorithmically designed to create an x-axis that is responsive to various amounts of user panning, zooming, and periodicity selection.

Depending on those factors, it will print different dates or times formats, will prevent label overlaps, and will evenly space labels. It will do this by finding the closest match in a pre-set timeInterval map, which contains allowable label values. (This algorithm will only be used if CIQ.ChartEngine.XAxis#timeUnit and CIQ.ChartEngine.XAxis#timeUnitMultiplier are not set).

The map contains an entry for every time unit that can be display (second, minute, hour, etc). Each map entry contains:

                arr: list of possible timeUnit Multipliers
                minTimeUnit: lower range for the interval
                maxTimeUnit: upper range for the interval

The default map is as follows, but you can override this as well:

                    // a label will be attempted to be placed every
                    // 1,2,5,10,20,50,100,250 or 500 MILLISECONDS
                    // as space permits.
                    arr: [1,2,5,10,20,50,100,250,500],
                    arr: [1, 2, 5, 10,15,30],
                    minTimeUnit: 0,
                    maxTimeUnit: 60
                    arr: [1,2,5,10,15,30],
                    minTimeUnit: 0,
                    maxTimeUnit: 60
                    arr: [1, 2, 3, 4,6,12],
                    minTimeUnit: 0,
                    maxTimeUnit: 24
                    arr: [1,2,7,14],
                    minTimeUnit: 1,
                    maxTimeUnit: 32
                    arr: [1,2,3,6],
                    arr: [1,2,3,5],
                    arr: [10],
                    minTimeUnit: 0,
                    maxTimeUnit: 2000000

The timeUnit multipliers will be used in the order in which they appear as long as the resulting label date is within the minTimeUnit and maxTimeUnit range.

For example, if the chart is currently displaying a zoom level where day labels should be displayed as determined by time differential and distance between bars, the following entry on the map will be activated:

                    arr: [1,2,7,14],
                    minTimeUnit: 1,
                    maxTimeUnit: 32

The algorithm will first attempt to add a label every 1 day. If there is not enough room, it will attempt every 2 days and so on. Once the correct multiplier is found, that multiplier will be used until maxTimeUnit is reached. So if there is only room to fit daily labels every 7 days, you will see them on dates that are multiples of 7. i.e. there will be a label on :

  • 7th of the month
  • 14th or the month
  • 21st of the month
  • 28th of the month

Assuming those dates match existing bars - otherwise they will be skipped.

Example for overriding the default algorithm with hard coded values:

stxx.chart.xAxis.timeUnit = CIQ.DAY;
stxx.chart.xAxis.timeUnitMultiplier = 7;

The above will display a chart with daily labels every 7 days.

Labels every 7 days

This kind of hard coded approach is only recommended for static charts because you will need to manually adjust your override as your periodicity changes to maintain a reasonable interval between tags.


Once label spacing has been calculated, the rendering process will begin. Just because a specific spacing has been set, doesn't mean there will be enough space to use it. When in tick periodicity, for example, since tick charts do not have a constant time interval, there sometimes won't be enough ticks to create enough space for a label to display, so the label will be skipped at rendering time. To address this, you can try changing the zoom level by setting a smaller span and thereby creating more space between the ticks. See CIQ.ChartEngine#setSpan and Understanding Chart Range.

You can also try to change the xaxis label width settings to allow less whitespace between the labels using CIQ.ChartEngine.XAxis#minimumLabelWidth



Customizing the the floating label over the x axis

The floating label over the x axis uses the same formatting functions available for the rest of the x axis labels. As outlined above, you can use the CIQ.ChartEngine.XAxis#formatter or locale/internationalizer.

But if you need to format the floating label independent of other formatting, override the CIQ.displayableDate to return the label formatted any way you need it.

Using multiple methods at once.

You can also combine multiple methods to create the desired look.

For example, the following code will first display a 5 day span of data, and then format the x axis labels so they display every 7 days and they are formatted in dd/mm fashion.

stxx.setSpan ({
    multiplier: 5,
    base: "day"

    stxx.chart.xAxis.timeUnit = CIQ.DAY; // set to 'null' when you no longer want this. 
    stxx.chart.xAxis.timeUnitMultiplier = 1; // set to 'null' when you no longer want this. 
    stxx.chart.xAxis.formatter=function(labelDate, gridType, timeUnit, timeUnitMultiplier){ // set to null when you no longer want this. 
            var text=labelDate.getDate()+'/'+labelDate.getMonth(); 
            return text 

Labels every 7 days custom