We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Text Align (textAlign) Not Working

Thread ID:





118174 Feb 8,2015 07:59 PM UTC Feb 10,2015 04:26 AM UTC ASP.NET Web Forms 4
Tags: Diagram
Jim Jacobs
Asked On February 8, 2015 07:59 PM UTC


I am unable to get the textAlign to work at all.

Here's my code:

function AlignText(alignment) {
    for (var i = 0; i < diagram.model.selectedItems.children.length; i++) {
        var object = diagram.model.selectedItems.children[i];
        if (object.type == 'node') { // A node or a text object
            if (object.shape.type == 'text') { // text object
                if (object.shape.textBlock) {
                    diagram.updateLabel(object.name, object.shape.textBlock, { textAlign: alignment });
            } else { // node
                if (object.labels[0]) {
                    diagram.updateLabel(object.name, object.labels[0], { textAlign: alignment });
        } else { // Must be a connector
            if (object.labels[0]) {
                diagram.updateLabel(object.name, object.labels[0], { textAlign: alignment });

I've put alerts in the above so I know it is being called.
I am using almost identical code to set other properties such as fontFamily and that works fine.

What am I doing wrong?

Thanks as usual.


Jim Jacobs
Replied On February 8, 2015 09:34 PM UTC

Hi again,

Just in case you're wondering, I am passing one of three values to my function:
  left, right or center (all lowercase)


Shyam G [Syncfusion]
Replied On February 9, 2015 01:24 PM UTC

Hi Jim

Thanks for using Syncfusion products.

We suggest you to set an “offset for an label of text node in order to achieve your requirement and you can define the label offset value from 0 to 1. Please refer the code snippet and sample below.

Code snippet:

function updatelabel() {            

            var diagram = $("#Diagram1").ejDiagram("instance");

            var node = diagram.selectionList[0];

            if (node) {

                if (node.shape.textBlock) {                 

                    var obj = new Object();

                    obj.textAlign = "left";

                    //offset for left align

                    obj.offset = ej.datavisualization.Diagram.Point(0, 0.5);  

                    //update text node label

                    diagram.updateLabel(node.name, node.shape.textBlock, obj);




Sample: http://www.syncfusion.com/downloads/support/directtrac/118174/WebApplication2905723546.zip

Please let me know if any concerns.


Shyam G

Jim Jacobs
Replied On February 9, 2015 04:31 PM UTC

Hi Shyam,

Thanks for the code.
It got me going in the right direction.
I found I had to tweak the X offset depending on the object type.

For the benefit of others than might be playing with this, here's what I ended up using:

Text object:
  Left:  obj.offset = ej.datavisualization.Diagram.Point(0.30, 0.5);
  Right:  obj.offset = ej.datavisualization.Diagram.Point(0.70, 0.5);

  Left:  obj.offset = ej.datavisualization.Diagram.Point(0.15, 0.5);
  Right:  obj.offset = ej.datavisualization.Diagram.Point(0.85, 0.5);

  Left:  obj.offset = ej.datavisualization.Diagram.Point(0.25, 0.5);
  Right:  obj.offset = ej.datavisualization.Diagram.Point(0.75, 0.5);

And of course the center alignment used:  obj.offset = ej.datavisualization.Diagram.Point(0.5, 0.5); for all object types.

Thanks again.


Shyam G [Syncfusion]
Replied On February 10, 2015 04:26 AM UTC

Hi Jim

Thanks for the update

Please let me know if you require further assistance on this.


Shyam G


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon