JavaScript/jQuery Chart - Customize Point Labels
If you need to change the text displayed by point labels, declare the customizeText function. It must return a string value. The argument of this function contains information about the point whose label is being customized. In the following example, the customizeText function instructs point labels to display both the argument and value of the point.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- series: {
- label: {
- visible: true,
- customizeText: function (pointInfo) {
- return pointInfo.argument + ': ' + pointInfo.value;
- }
- }
- }
- });
- });
You can also customize an individual label. For this purpose, assign a function to the customizeLabel property. This function must return an object with properties for the label that you want to customize. Note that the customizeLabel property should be declared at the root level of the Chart configuration.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- series: {
- label: {
- visible: true,
- backgroundColor: 'blue'
- }
- },
- // Assigns the red color to all labels whose series points have value more than 100
- // Other labels remain painted in blue
- customizeLabel: function (pointInfo) {
- return pointInfo.value > 100 ? { backgroundColor: 'red' } : { }
- }
- });
- });
You can also use the following properties to customize label texts:
- commonSeriesSettings.label.displayFormat - for all labels.
- series.label.displayFormat - for indifidual label.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- commonSeriesSettings: {
- type: 'line',
- label: {
- format: 'thousands',
- visible: true,
- displayFormat: "{seriesName}: {valueText}",
- }
- },
- series: [
- { valueField: 'y1564', name: '15-64 years' },
- { valueField: 'y014', name: '0-14 years' },
- { valueField: 'y65', name: '65 years and older',
- label: {
- displayFormat: "<u>65+ years</u>: {valueText}",
- },
- },
- ],
- });
- });
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.