- Home
- Forum
- ASP.NET Web Forms
- Text Align (textAlign) Not Working
Text Align (textAlign) Not Working
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
Just in case you're wondering, I am passing one of three values to my function:
left, right or center (all lowercase)
Jim
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.
Regards,
Shyam G
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);
Node:
Left: obj.offset = ej.datavisualization.Diagram.Point(0.15, 0.5);
Right: obj.offset = ej.datavisualization.Diagram.Point(0.85, 0.5);
Connector:
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.
Jim
Hi Jim
Thanks for the update
Please let me know if you require further assistance on this.
Regards,
Shyam G
- 4 Replies
- 2 Participants
-
JJ Jim Jacobs
- Feb 8, 2015 07:59 PM UTC
- Feb 10, 2015 04:26 AM UTC