Articles in this section

How to Display Text in an Empty Bar of a Chart Series?

Description

This article explains how to render custom text in place of empty bars in a Bar or Column chart series.

Solution

A Bar or Column series can be used to visualize data as bars. An empty bar can be rendered by setting the data point’s y-value to zero and the series type to either Column or Bar.

To display text in place of an empty bar, you can use the [annotation](https://ej2.syncfusion.com/javascript/documentation/api/chart/chartAnnotation/) feature. Annotations allow you to overlay custom content at a specified position on the chart.

You can control the placement of the annotation using the x and y properties. Set the coordinateUnits to “Point” to align it with a specific data point. The content to be displayed can be defined using the content property.

Code Snippet

var chart = new ej.charts.Chart({
annotations: [
       {
           content: '<div id="annotation1" style="color:red;font-weight:bold"> E<br>M<br>P<br>T<br>Y</div>',
           x: 'Wheat', y: 20, coordinateUnits: 'Point'
       }, 
       //...
       ];
});

The following image illustrates the output of the above code:

image.png

Refer to the working sample for additional details and implementation: View Sample in Stackblitz

Conclusion

We hope you enjoyed learning about how to display text in an empty bar of a chart series in JavaScript.

You can refer to our Javascript Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied