My GraphComponent Does Not Show the Graph

Tips & Tricks

Summary

What to do if the `GraphComponent` or the `GraphOverviewComponent` displays a blank area instead of the graph.

This article was written for an older version. It is only online as a reference for customers using this old version. The information it contains is probably out of date.

The latest information can be found in the yFiles documentation

Description

If you're not sure how to correctly include the GraphComponent in your application, please check out Creating the Web Application in the developers' guide.

Possible issues

Most likely, you are facing a CSS issue. This can have multiple causes.

Is yfiles.css loaded?

Prior to yFiles for HTML 2.4 the CSS file yfiles.css was needed for yFiles to function properly. If using an earlier version make sure that you loaded it correctly.

No matter how the div get's sized (third party widget frameworks, etc.), it's important that the div will get a positive width and height, since yFiles itself does not set a minimum size itself by default.

Does the component have a valid size?

You need to set the size of the div element the GraphComponent lives in, e.g. like this:

<style>
#graphComponent {
  width: 100%;
  height: 100%;
}
</style>

or more explicitly like so

<style>
#graphComponent {
  width: 256px;
  height: 256px;
}
</style>

Of course a local declaration will work, too:

<div id="graphComponent" style="width:256px; height:256px"></div>

Open the JavaScript debugger (F12) and select the "Elements" tab. Use the "Select Element" tool or navigate through the DOM view to find the GraphComponent. The div element that represents the root of the GraphComponent's DOM subtree should have a reasonable, non-zero width and height. If not, check if the CSS rules that set the div size are applied.

Did you remove the component from the DOM and re-insert it later?

In this case, the problem most likely is that the resize mechanism is switched off. When the component is removed from the DOM, the property sizeChangedDetection is automatically set to SizeChangedDetectionMode.NONE for performance resons. Set it to AUTO, SENSOR or TIMER again to re-enable resize detection. If you don't know which value to use either use AUTO which is the default, or add code that remembers the old value before the element is removed from the DOM.

Categories this article belongs to:
yFiles for HTML
Applies to:
yFiles for HTML: 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
Keywords:
GraphComponent - Empty - White - Blank - CanvasComponent - GraphOverviewComponent - Overview - Component - SizeChangedDetectionMode - sizeChangedDetection