How to locate vertices using by "NodeXLWithAxesControl"?

Oct 23, 2012 at 1:47 PM
Edited Oct 23, 2012 at 5:21 PM

Hello :)


I want to use the "NodeXLWithAxesControl" tool to locate vertices with values (for example, vertex A has x-value 20, and y-value 30) on the NodeXLWithAxesControl, where vertices can automatically be draw at the point they should be by getting their value (ex. vertex A is at X-Axis 20 and Y-Axis 30, that is to say, A(20, 30)).

But I find a problem to locate them, I don't know how to use NodeXLWithAxesControl......

I know how to use NodeXLControl tool to draw vertices and edges automatically, but I don't know how to control the location of vertices on NodeXLWithAxesControl, because when I use NodeXLControl.DrawGraph(true), the vertices will be drawn without my control of location setting, but now I have to set their location in the graph.  :(

Oh, I am using WPF (C#) to do this.


Thanks for your reading and help!!!

Oct 23, 2012 at 11:49 PM

If the problem you're having is that you want to set the vertex locations yourself, then the solution has two steps:

1. For each vertex in your graph, set IVertex.Location to some PointF value.

2. Call NodeXLControl.DrawGraph(false), which will tell the NodeXLControl to not lay out the vertices before drawing the graph.

If that's not what you meant, let me know.

-- Tony

Oct 24, 2012 at 12:38 PM
Edited Oct 24, 2012 at 3:20 PM

Dear Tony, 

That is what I want, thank you :)

But when I follow the steps to do, I found a problem that the IVertex.Location cannot meet the X-Axis and Y-Axis I set.

IVertex.Location seems to set the vertex's location from the distance of NodeXLWithAxesControl, but not to meet the X-Axis and Y-Axis of NodeXLWithAxesControl.


Here is the code:

            NodeXLControl nodeXLControl_strategy_BCG = nodeXLWithAxesControl_strategy_BCG.NodeXLControl;
IVertexCollection Vertices = nodeXLControl_strategy_BCG.Graph.Vertices; IEdgeCollection Edges = nodeXLControl_strategy_BCG.Graph.Edges; nodeXLWithAxesControl_strategy_BCG.XAxis.SetRange(0, 0, 100, 0, false); nodeXLWithAxesControl_strategy_BCG.YAxis.SetRange(0, 0, 100, 0, false); IVertex v1 = Vertices.Add(); v1.SetValue(ReservedMetadataKeys.PerVertexShape, VertexShape.Sphere); v1.SetValue(ReservedMetadataKeys.PerColor, Colors.Red); v1.Location = new System.Drawing.PointF(90F, 30F); v1.SetValue(ReservedMetadataKeys.PerVertexLabel, v1.Location.ToString()); IVertex v2 = Vertices.Add(); v2.SetValue(ReservedMetadataKeys.PerVertexShape, VertexShape.Sphere); v2.SetValue(ReservedMetadataKeys.PerColor, Colors.Red); v2.Location = new System.Drawing.PointF(300F, 600F); v2.SetValue(ReservedMetadataKeys.PerVertexLabel, v2.Location.ToString()); nodeXLControl_strategy_BCG.DrawGraph(false);


I snap a photo of computing result for you in Picasa:

So the vertices are not at the right location in the NodeXLWithAxesControl

Can the vertices be located to meet the X-Axis and Y-Axis in the NodeXLWithAxesControl?

Thank you Tony!!


Oct 25, 2012 at 12:55 AM
Edited Oct 25, 2012 at 4:04 AM

First, I haven't actually used the control that way.  You're not using it as a scatter plot, are you?  If so, I'm sure there are better controls for that.

But if you are actually using it to display networks, then you have to set the range of each of the control's axes to the actual width and height of the embedded NodeXLControl.  In the post after this one, I'll include the sample code I wrote to get it to work.

Note that I was mistaken about calling DrawGraph(false).  Instead, set the NodeXLControl.Layout property to a NullLayout object, and call DrawGraph(true) instead.  I think this is a bug that never showed up before because we don't use the control that way, and I'll investigate it later.

-- Tony

Oct 25, 2012 at 12:57 AM

using System;
using System.Windows;
using System.Linq;
using System.Diagnostics;
using System.Drawing;
using Smrf.NodeXL.Core;
using Smrf.NodeXL.Layouts;
using Smrf.NodeXL.Visualization.Wpf;

namespace WpfApplication2

public partial class MainWindow : Window
    public MainWindow()

        NodeXLControl nodeXLControl =

        // This is just for diagnostics.

        nodeXLControl.VerticesMoved +=
            new VerticesMovedEventHandler(nodeXLControl1_VerticesMoved);

        IVertexCollection vertices = nodeXLControl.Graph.Vertices;

        IVertex vertex1 = vertices.Add();
        vertex1.Location = new PointF(100, 150);

        nodeXLControl.Layout = new NullLayout();

    private void nodeXLWithAxesControl1_SizeChanged(object sender,
        SizeChangedEventArgs e)
        NodeXLControl nodeXLControl =

        this.nodeXLWithAxesControl1.XAxis.SetRange(0, 0,
            nodeXLControl.ActualWidth, 0, false);

            nodeXLControl.ActualHeight, 0, 0, 0, false);

    private void nodeXLControl1_VerticesMoved(object sender,
        VerticesMovedEventArgs e)
        // This is just for diagnostics.

        Debug.WriteLine("VerticesMoved: "
            + e.MovedVertices.First().Location);


Oct 25, 2012 at 7:18 AM

Thank you, Tony! That is what I need :) You are so great!

I can do it well by the code you wrote for me.


You said that "First, I haven't actually used the control that way."

May I ask you that what is the right way to use the control?

I want to learn more about this control :)


Thank you very much.

Oct 25, 2012 at 5:08 PM
Edited Oct 26, 2012 at 3:26 PM

The lack of edges and the use of axes in your examples made me wonder if you needed a simple scatter plot.  We use the control to show networks, which are vertices connected by edges, like so:

But however you're using it, if you find the control useful, then I'm glad to hear it.

-- Tony

Oct 28, 2012 at 3:08 PM

Yes, you are right! I need a scatter plot.  :D

NodeXL is a great tool to draw network graph, I like it!

I have used NodeXLControl to draw graph automatically, it is so good!


Thank you Tony!!  :)