New to Kendo UI for jQuery? Start a free 30-day trial

CategoryAxis.labels

configuration

Configures the axis labels.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            visible: true,
            color: "#ff0000",
            font: "12px Arial"
        }
    }
});
</script>

The background color of the labels. Any valid CSS color string will work here, including hex and rgb.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            background: "#ffe0e0"
        }
    }
});
</script>

The border of the labels.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            border: {
                color: "#ff0000",
                width: 2,
                dashType: "dash"
            }
        }
    }
});
</script>

The text color of the labels. Any valid CSS color string will work here, including hex and rgb.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            color: "#0000ff"
        }
    }
});
</script>

Culture to use for formatting the dates. See Globalization for more information. It uses the global culture by default.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    categoryAxis: {
        type: "date",
        labels: {
            culture: "de-DE"
        },
        categories: [
            new Date("2023/01/01"),
            new Date("2023/02/01"),
            new Date("2023/03/01")
        ]
    },
    series: [{
        data: [10, 15, 8]
    }]
});
</script>

Date format strings

"hours"

"HH:mm"

"days"

"M/d"

"weeks"

"M/d"

"months"

"MMM 'yy"

"years"

"yyyy"

The Chart will choose the appropriate format for the current baseUnit. Setting the labelsformatoption will override these defaults.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    categoryAxis: {
        type: "date",
        baseUnit: "months",
        labels: {
            dateFormats: {
                months: "MMM yyyy"
            }
        },
        categories: [
            new Date("2023/01/01"),
            new Date("2023/02/01"),
            new Date("2023/03/01")
        ]
    },
    series: [{
        data: [10, 15, 8]
    }]
});
</script>

The font style of the labels.

Default: "12px Arial,Helvetica,sans-serif"

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            font: "16px Verdana"
        }
    }
});
</script>

The format of the labels.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            format: "{0:N2}"
        }
    }
});
</script>

The margin of the labels.

Default: 0

js
// sets the top, right, bottom and left margin to 3px.
margin: 3

// sets the top and left margin to 1px
// margin right and bottom are with 0px (by default)
margin: { top: 1, left: 1 }

Mirrors the axis labels and ticks. If the labels are normally on the left side of the axis, mirroring the axis will render them to the right.

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            mirror: true
        }
    }
});
</script>

The padding of the labels.

Default: 0

js
// sets the top, right, bottom and left padding to 3px.
padding: 3

// sets the top and left padding to 1px
// padding right and bottom are with 0px (by default)
padding: { top: 1, left: 1 }

The rotation angle of the labels.

Default: 0

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            rotation: 45
        }
    }
});
</script>

Number of labels to skip. Skips rendering the first n labels.

Default: 1

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            skip: 2
        }
    }
});
</script>

Label rendering step. Every n-th label is rendered where n is the step

Default: 1

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            step: 2
        }
    }
});
</script>

The template which renders the labels.

The fields which can be used in the template are:

  • value - the category value
  • dataItem - the data item, in case a field has been specified. If the category does not have a corresponding item in the data then an empty object will be passed.
  • format - the default format of the label
  • culture - the default culture (if set) on the label
  • index - the 0-based index of the current label
  • count - the total number of labels on the axis
<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            template: (data) => `Category: ${data.value}`
        }
    }
});
</script>

The visibility of the labels.

Default: true

<div id="sparkline"></div>
<script>
$("#sparkline").kendoSparkline({
    data: [1, 2, 3, 4, 5],
    categoryAxis: {
        labels: {
            visible: false
        }
    }
});
</script>