)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to set CSSClass property for the nodes/connectors/labels/ports

Platform: jQuery |
Control: ejDiagram |
Published Date: November 28, 2015 |
Last Revised Date: May 30, 2019
Tags: cssclass

You can customize the appearance of a node by setting Cascading Style Sheet (CSS) class name as the value for cssClass property. Similarly, you also can apply CSS for connectors, labels, decorators and ports using theirs cssClass property.

The following code illustrates how to set CSS class for Diagram elements.

HTML

<style>
     .fillNode {
            fill: green;
        }
     .lineColor {
            stroke: red;
        }
     .text:hover  {
            cursor:text;
        }
</style>

 

Java-script

 
//set a class name to node’s cssClass property to customize its appearance
var node = { name: "node1", width: 100, height: 100, offsetX: 150, offsetY: 150, cssClass: "fillNode"};
 
//set a class name to label’s cssClass property to customize its cursor
node.labels: [{ text: "Node", cssClass: "text" }];
 
//set a class name to port ‘s cssClass property to customize its appearance
node.ports = [{ name: "aport", offset: { x: 0, y: 0.5 }, visibility: ej.datavisualization.Diagram.PortVisibility.Visible, cssClass: "fillNode" }]
 
//set a class name to connector ‘s cssClass property to customize its appearance
var connector = { name: "connector1", sourcePoint: { x: 200, y: 300 }, targetPoint: { x: 300, y: 400 }, cssClass: "lineColor" };

 

C#

Node node = new Node();
node.Name = "Node1";
node.OffsetX = 150;
node.OffsetY = 150;
//set a class name to node’s cssClass property to customize its appearance
node.CssClass = "fillNode";
 
Label label = new Label();
label.text = "Node";
//set a class name to label’s cssClass property to customize its cursor
label.CssClass = "text";
 
Port port = new Port();
port.Offset = new DiagramPoint(0f, 0.5f);
port.Visibility = PortVisibility.Visible;
//set a class name to port ‘s cssClass property to customize its appearance
port.CssClass = "fillNode";
node.Ports.Add(port);
 
Connector connector = new Connector ();
connector.Name = "Connector1";
connector.SourcePoint = new DiagramPoint(200f, 300f);
connector.TargetPoint = new DiagramPoint(300f, 400f);
//set a class name to connector ‘s cssClass property to customize its appearance
connector.CssClass = " lineColor ";

 

The limitations of using the CSSClass are as follows.

  1. When we export the diagram, the style applied via CssClass will not be exported.
  2. Serialization (save and load) can be performed in the diagram. The class properties which we define will be serialized as a string and the style properties should be maintained it in the application level. 
  3. If we define the style property such as stroke,fill,stroke-width in both CssClass and the node’s properties, then the style defined in the CssClass will be rendered.
  4. If we hover on the label, the CssClass which we have applied for the node will not be reflected because we have rendered the node’s and connector’s in the different layers.
  5. CssClass will not applied for the elements which have inline styles.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon