Axis labels in JavaScript Chart control
18 Nov 20183 minutes to read
Smart axis labels
When axis labels overlap due to limited space or dense data points, the labelIntersectAction property can be used to control how the labels are rendered. This helps improve readability by automatically adjusting label visibility or orientation.
When setting labelIntersectAction as Hide, overlapping labels are hidden to avoid visual clutter.
When setting labelIntersectAction as Rotate45, the labels are rotated by 45 degrees to reduce overlap.
When setting labelIntersectAction as Rotate90, the labels are rotated vertically to maximize space utilization.
Axis labels positioning
By default, axis labels are positioned outside the axis line. Labels can also be placed inside the axis line using the labelPosition property, which is useful when optimizing space within the chart area.
Multilevel labels
Multiple levels of labels can be displayed on an axis using the multiLevelLabels property. This feature is useful for grouping related categories and improving data interpretation. The following configuration options are available:
• Categories
• Overflow
• Alignment
• Text style
• Border
Note: To use the multilevel label feature, inject
MultiLevelLabelusingChart.Inject(MultiLevelLabel)method.
Categories
Using the categories property, the start, end, text, and maximumTextWidth values of multilevel labels can be configured to define the label range and content.
Overflow
Using the overflow property, multilevel labels can be configured to either trim or wrap when the text exceeds the available space.
Alignment
The alignment property provides options to position multilevel labels at far, center, or near relative to the axis.
Text customization
The textStyle property of multilevel labels provides options to customize the size, color, fontFamily, fontWeight, fontStyle, opacity, textAlignment, and textOverflow.
Border customization
Using the border property, the width, color, and type of the multilevel label border can be customized. The supported border types are Rectangle, Brace, WithoutBorder, WithoutTopBorder, WithoutTopandBottomBorder, and CurlyBrace.
Edge label placement
Labels with long text at the edges of an axis may appear partially outside the chart area. To avoid this, use the edgeLabelPlacement property in the axis. This property moves the label inside the chart area or hides it for better appearance. By default, the edgeLabelPlacement property is set to Shift, ensuring that labels are repositioned inside the chart area to prevent overlap.
Sorting
The chart’s data source can be sorted using the sort method of chart. The arguments that are required to pass to sort method are data of chart. The fields depend on which sorting is performed either x or y, and the isDescending with which data source values are sorted in either ascending or descending.
Labels customization
The labelStyle property of an axis provides options to customize the color, font-family, font-size, and font-weight of axis labels.
Customizing specific point
Specific axis label text can be customized using the axisLabelRender event, which allows conditional formatting or dynamic text updates during label rendering.
Line break support
The line break feature is used to display long axis label text across multiple lines. In the following example, the x value in the data source contains long text, which is split into two lines using the <br> tag.
Maximum labels
MaximumLabels property is set, then the labels will be rendered based on the count in the property per 100 pixel. If you have set range (minimum, maximum, interval) and maximumLabels, then the priority goes to range only. If you haven’t set the range, then we have considered priority to maximumLabels property.
Axis label template
The axis label template allows axis labels to be customized using HTML content. This enables conditional styling and the inclusion of dynamic elements such as icons, images, or additional contextual data. This customization is enabled by setting the template content in the labelTemplate property of the AxisModel.