Programmatically render graph from facebook data in C#/ASP.NET

Dec 13, 2011 at 6:28 AM


I am planning to build a prototype for social network analysis for fraud detection and would like to analyze the patterns of relationships among people in groups. I have implemented the sample custom data provider from and tested it from Excel as well. From another sample in NodeXLApi help file, I was able to render a graph from ASP.NET page as well that contained hard-coded values for the vertices.

Now, I would like to know how I can do the following:

1. Use the custom provider (either the samplle or anything I build it) from an ASP.NET page or a winforms app and
2. Finally consume the facebook data (maybe friends list) and plot it on a graph in ASP.NET page or winforms.

Some working code snippets or access to online resources would be really helpful.

Thanks in advance.



Dec 13, 2011 at 7:35 PM
Edited Dec 13, 2011 at 7:36 PM


On question 1, you use your custom graph data provider by simply calling its TryGetGraphData() method, which returns the graph data as GraphML.  If you are using it from ASP.NET, you would have to make sure the provider doesn't have any kind of user interface, which of course won't work on a Web server.  And if the provider takes a long time to get its data, you might want to make use of a threading mechanism such as ASP.NET's asynchronous pages to improve performance.

I'll interpret question 2 as "how do I get my custom GraphML into a NodeXL graph."  For that you can use the Smrf.NodeXL.Adapters.GraphMLGraphAdapter class, which has a LoadGraphFromString() method.  Pass it the GraphML string and it returns a Graph object, which you can pass to either the NodeXLVisual.GraphDrawer.DrawGraph() method on ASP.NET pages, or to the NodeXLControl.Graph property in a WinForms application.

I don't have other code apart from the complete working samples in the NodeXLApi.chm help file, which I think you've already found.

If you have a more specific question, let me know.

-- Tony

Dec 14, 2011 at 4:08 AM

Hi Tony,

Thanks a lot for replying, I appreciate.

I actually solved the problems (with doing detailed research) before your note arrived and used the LoadGraphFromString() method from the Smrf.NodeXL.Adapters.GraphMLGraphAdapter class. :-)

Then I did the following:

- Synchronously lay out the graph using one of the NodeXL-supplied layout objects.
- Created an object that can render a NodeXL graph as a Visual and used the NodeXLVisual object's GraphDrawer to draw the graph onto the Visual
- Converted the Visual to a Bitmap and written the Bitmap's contents to the response stream.

Now I am really looking for a working example of how facebook data can be consumed and plotted on a NodeXL graph programmatically. Do you think any sample code is available either online or in chm?



Dec 14, 2011 at 6:21 AM

See the Social Network Importer for NodeXL at, which is a NodeXL graph data provider that gets Facebook data.

-- Tony