# Help, trying to get force directed vega graph working

**URL:** <https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [October 1, 2021, 10:58pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716 "2021-10-01T22:58:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 1, 2021, 10:58pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/1 "2021-10-01T22:58:57Z")

</div>

Hello All,

I am trying to get a force directed graph working with my data in ES and vega,

[Here is a pastebin link to my vega code because its too long to post here](https://pastebin.com/tYud6HtM).

When I look at the dat with the VEGA\_DEBUG on the console in the developer tools it looks as I would expect, but I don't get any paths generated. Can anyone see something wrong with my linkpath? I am at an impasse, I have tried several variations on things but don't seem to be able to make any progress.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 2, 2021, 12:07pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/2 "2021-10-02T12:07:05Z")

</div>

Can you [provide a schema](https://www.elastic.co/guide/en/kibana/master/vega.html#asking-for-help-with-a-vega-spec) that includes some data?

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 4, 2021, 2:03pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/3 "2021-10-04T14:03:02Z")

</div>

Hello @aaron-nimocks,

Thanks for the feedback, here is some example data. (I have hand redacted the values so hopefully I didn't mess it up but should give you a feel for what it looks like)

```auto
[
   {
      "_index":"graphing_9_2021",
      "_type":"_doc",
      "_id":"REL_1",
      "_score":1.0,
      "_source":{
         "id":"REL_1",
         "timestamp":1633309253125,
         "type":"relationship",
         "label":"shared",
         "from":"USER_1",
         "to":"CARD_1",
         "from_label":"User",
         "to_label":"CardShare",
         "directionality":"right"
      }
   },
   {
      "_index":"graphing_9_2021",
      "_type":"_doc",
      "_id":"CHAT_1",
      "_score":1.0,
      "_source":{
         "month":"9",
         "year":"2021",
         "id":"CHAT_1",
         "day":"4",
         "timestamp":1633309253197,
         "type":"Chat"
      }
   },
   {
      "_index":"graphing_9_2021",
      "_type":"_doc",
      "_id":"REL_2",
      "_score":1.0,
      "_source":{
         "id":"REL_2",
         "timestamp":1633309253214,
         "type":"relationship",
         "label":"participated",
         "from":"USER_1",
         "to":"CHAT_1",
         "from_label":"User",
         "to_label":"Chat",
         "directionality":"right"
      }
   },
   {
      "_index":"graphing_9_2021",
      "_type":"_doc",
      "_id":"USER_1",
      "_score":1.0,
      "_source":{
         "id":"USER_1",
         "timestamp":1633309266911,
         "user_email":"USER_1@foo.com",
         "email_domain":"foo.com",
         "type":"User"
      }
   }
]

```

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 4, 2021, 2:15pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/4 "2021-10-04T14:15:53Z")

</div>

If you can provide it in the format I linked to it would be helpful. You have multiple queries and I wouldn't know how to put that sample data in the correct format.

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 4, 2021, 3:35pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/5 "2021-10-04T15:35:44Z")

</div>

Hello @aaron-nimocks,

Sorry for the confusion:

> **[{ "$schema": "https://vega.github.io/schema/vega/v5.json", "padding": 0, -...](https://pastebin.com/ieVxSVmD)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Had to pastebin it b/c its too long. anyway I appreciate the assist here!

Thank you

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 4, 2021, 3:49pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/6 "2021-10-04T15:49:22Z")

</div>

I can help dig in if needed but your initial problem is your table `chat-connections-2` is empty. So I would start with that and make sure the data is formatted the same as the [demo](https://vega.github.io/editor/#/examples/vega/force-directed-layout).

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/3/33e14839a786d5c8269e7d39903bf9a3da6b23f5.png)

Which means your lookup isn't producing the results as expected.

```auto
    {
      "name": "chat-connections-2",
      "source": "chat-connections",
      "transform": [    
        {
          "type": "lookup",
          "from": "nodes",
          "key": "from",
          "fields": ["id"],
          "as": ["source"]
        }
      ]
    }

```

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 4, 2021, 5:05pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/7 "2021-10-04T17:05:19Z")

</div>

Hello @aaron-nimocks,

When I am messing with it in the debugger, it appears that when I add the line:

```auto
links: user-connections

```

To the transform section of the nodes mark it makes that table undefined, not sure why, if I comment that one out the table isn't any thoughts?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 4, 2021, 5:32pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/8 "2021-10-04T17:32:10Z")

</div>

I would look at the demo I linked to above to see how it works.

The link table needs to look just like the demo on how it's structured. It has to have `source.x` and `source.y` along with the `target.x` and `target.y` so it knows how to draw the line. Your link source is missing that currently and you would need to backtrack to see where that is missing.

Your data and transformations are doing a lot so it's difficult to visualize what you are doing and why. I might have more time to sit down and look at it all at some point to give a better answer but as of right now what I posted is where the issue is.

 ![vega](https://us1.discourse-cdn.com/elastic/original/3X/4/e/4e64bda26fba972f46cf419392530d39635dc204.jpeg)

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 4, 2021, 8:57pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/9 "2021-10-04T20:57:53Z")

</div>

Hello @aaron-nimocks,

I believe I am on the right track to resolve this but have a question, how can I get the position of a datum in the table? It looks as though my attempt is failing because the example wants to link items by their position in the data table.

Thank you!

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 4, 2021, 9:06pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/10 "2021-10-04T21:06:41Z")

</div>

When you say position do you mean `index`? [Here](https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAB3GgBN6aAQAZVM+DTJYV6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5SGE5Js2ubm8FnbJh6rdumC7h2uHASe4jTSRR1U6Wp3SSu-kM+tTP-opbNbe9rwGFApjnk55znW53rsQNIDepUxjQjIZ6kH0EDeDypj6+8bDIIsYa3WjgOAsDNkyKl7noNpOQgHZgwW1wiAFDLXhkN68TBKo4RSyAJjkMNNXfJ5JjQor0PjWr4HDaG6DiTgoxhzytHDaCJQW5gdBhxbyRtRbQbYgAyjQAIW0laDjNKYRNzI5ZMAx1agIsXjyjRNCkGgjwNBC7il6goDl5gVc12PdUHN44zBOm0ex6AdfoEw5ZUsHmhsLrZc0DHtf1XONBnkw4Fb036YQPECBMG5HeuCPqQzxskYY0fc8rnZF79MnwfpjDoMDmxdn7eGAFfEOyAfTMVaAUIyNRub2BvnfNyLg-hbXrvbRGFtTLI2KMZUy6Yc4EItsnDE+9D4zzXiADeSBL4GEeLDcBs97hyBTHYZuT8UgsMMNPUAhgyCa3sMEfwAAqfwHQCHlEqNUcRkijIyKqGmbqkIxBrVXsfcibAu4UKvgpH+4MvilVgn2FwdAMRXAkNWJk+hWK5WuB7IwpgLgOJuNfZxsdAzenkt4vssC-H1nOuQhOzhX6eNiE4F2cYBERPaAkbe48fHezcgsPO2sKjKKcUIlx7RFGZOqIkwJ8D74KESIws84gyDKHCTkrxUjui9DXEUnMQTQ6LCWC4b61J7DdNRouSolxti8LieAbpawhn1ibrpD6kNyKeBgAjU2uC-q9I6f0l2uie4F37qgQ2Zg4Bfm2KQmeJcX4CKYR-V+Msi5x2Vvbaq9hnbX0uXAAA6ooGpmiv6oEXlwzM9kjHfDmd0nACyXBngAI4MFPiMuppipkGF6GRb6uxcIAA1GZtkoLhSgzgDDmQAJpYoQDi8ylBylkxQpi4W2LFJ4oJihYltLSX0sSHpXSQA) is an example I made before that the data isn't perfect like the demo where I had to do transformations. You can see how I made the index field there.

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 4, 2021, 9:31pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/11 "2021-10-04T21:31:42Z")

</div>

Yes, I mean the index in the table I was cautious of saying "index" because the source example has an index property as well.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 4, 2021, 10:22pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/12 "2021-10-04T22:22:21Z")

</div>

Got ya. If you didn't see I solved that by using the [identifier](https://vega.github.io/vega/docs/transforms/identifier/) transform which just increments numbers starting at 1. Then I used the [formula](https://vega.github.io/vega/docs/transforms/formula/) transformation to subtract 1 from that because it needs to start at 0.

```auto
{"type": "identifier", "as": "index"},
{"type": "formula", "as": "index", "expr": "datum['index'] - 1"},

```

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 13, 2021, 3:35pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/13 "2021-10-13T15:35:31Z")

</div>

@aaron-nimocks Thank you, that got me to where I needed to be!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 10, 2021, 3:36pm UTC](https://discuss.elastic.co/t/help-trying-to-get-force-directed-vega-graph-working/285716/14 "2021-11-10T15:36:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
