ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapFactory Class / CreateLinkChart Method / CreateLinkChart(String,KnowledgeGraph,KnowledgeGraphLayerIDSet) Method
The name of the map.
A knowledge graph datastore.
A set of Named Object types and record ids that sets the content of the Knowledge Graph layer. See KnowledgeGraphLayerIDSet.
Example

In This Topic
    CreateLinkChart(String,KnowledgeGraph,KnowledgeGraphLayerIDSet) Method
    In This Topic
    Creates a link chart map (a map of type MapType.LinkChart) with a specified knowledge graph datastore. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Function CreateLinkChart( _
       ByVal name As String, _
       ByVal knowledgeGraph As KnowledgeGraph, _
       ByVal idSet As KnowledgeGraphLayerIDSet _
    ) As Map

    Parameters

    name
    The name of the map.
    knowledgeGraph
    A knowledge graph datastore.
    idSet
    A set of Named Object types and record ids that sets the content of the Knowledge Graph layer. See KnowledgeGraphLayerIDSet.

    Return Value

    A map of type MapType.LinkChart.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    knowledgeGraph cannot be null.
    idSet contains invalid Name Object types..
    Remarks
    The KnowledgeGraph layer created in the Link Chart contains sub layers for each Named Object type. To set the output content of the KnowledgeGraph composite layer, add an entry to the idSet for each Named Object type to be included in the output along with a list of their relevant record ids. Specify a null or empty list for a given entry to include all the records for that particular type at the time of creation.
    Note: Named Object names in a ID set entry are case-sensitive.
    If there are Named Object type names specified in the ID set that do not match a Named Object type name in the KnowledgeGraph then a KnowledgeGraphLayerException will be thrown when the layer is created. The exception will contain the list of invalid Named Object types.

    If you specify a null or empty IDSet, then the KnowledgeGraph layer will contain all the sub layers for the Named Object types but the sub layers will contain no content.

    See KnowledgeGraphLayerIDSet
    Example
    Create a LinkChart from a subset of an existing LinkChart IDSet
    var map = MapView.Active.Map;
    if (map.MapType != MapType.LinkChart)
      return;
    
    // find the KG layer
    var kgLayer = map.GetLayersAsFlattenedList().OfType<KnowledgeGraphLayer>().FirstOrDefault();
    if (kgLayer == null)
      return;
    
    // find the first LinkChartFeatureLayer in the KG layer
    var lcFeatureLayer = kgLayer.GetLayersAsFlattenedList().OfType<LinkChartFeatureLayer>().FirstOrDefault();
    if (lcFeatureLayer != null)
      return;
    
    QueuedTask.Run(() =>
    {
      // get the KG
      var kg = kgLayer.GetDatastore();
    
      // get the ID set of the KG layer
      var idSet = kgLayer.GetIDSet();
    
      // get the named object type in the KG that the LinkChartFeatureLayer represents
      var typeName = lcFeatureLayer.GetTypeName();
      // if there are items in the ID Set for this type
      if (idSet.Contains(typeName))
      {
        // build a new ID set containing only these records
        var dict = idSet.ToOIDDictionary();
        var oids = dict[typeName];
    
        var newDict = new Dictionary<string, List<long>>();
        newDict.Add(typeName, oids);
    
        var newIDSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, newDict);
    
        // now create a new link chart using just this subset of records
        MapFactory.Instance.CreateLinkChart("subset LinkChart", kg, newIDSet);
      }
    });
    Create a Link Chart Containing All Records for a KG
    QueuedTask.Run(() =>
    {
      //Create the link chart and show it
      //build the IDSet using KnowledgeGraphFilterType.AllNamedObjects
      var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
        kg, KnowledgeGraphFilterType.AllNamedObjects);
      var linkChart = MapFactory.Instance.CreateLinkChart(
                        "KG Link Chart", kg, idSet);
      FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
    });
    
    Create a Link Chart With an Empty KG Layer
    QueuedTask.Run(() =>
    {
      //Create the link chart with a -null- id set
      //This will create a KG Layer with empty sub-layers
      //(Note: you cannot create an empty KG layer on a map - only on a link chart)
      var linkChart = MapFactory.Instance.CreateLinkChart(
                        "KG Link Chart", kg, null);
      FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
    });
    
    Create a link chart with all the entities of the Knowledge Graph
    string url =
            @"https://acme.server.com/server/rest/services/Hosted/AcmeKnowledgeGraph/KnowledgeGraphServer";
    
    QueuedTask.Run(() =>
    {
      using (var kg = new KnowledgeGraph(new KnowledgeGraphConnectionProperties(new Uri(url))))
      {
        var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
          kg, KnowledgeGraphFilterType.AllEntities);
        var newLinkChart = MapFactory.Instance.CreateLinkChart(
          "All_Entities link chart", kg, idSet);
      };
    });
    
    Create a Link Chart from a query
    //use the results of a query to create an idset. Create the link chart
    //containing just records corresponding to the query results
    var qry = @"MATCH (p1:PhoneNumber)-[r1:MADE_CALL|RECEIVED_CALL]->(c1:PhoneCall)<-" +
              @"[r2:MADE_CALL|RECEIVED_CALL]-(p2:PhoneNumber)-[r3:MADE_CALL|RECEIVED_CALL]" +
              @"->(c2:PhoneCall)<-[r4:MADE_CALL|RECEIVED_CALL]-(p3:PhoneNumber) " +
              @"WHERE p1.FULL_NAME = ""Robert Johnson"" AND " +
              @"p3.FULL_NAME= ""Dan Brown"" AND " +
              @"p1.globalid <> p2.globalid AND " +
              @"p2.globalid <> p3.globalid " +
              @"RETURN p1, r1, c1, r2, p2, r3, c2, r4, p3";
    
    var dict = new Dictionary<string, List<long>>();
    
    QueuedTask.Run(async () =>
    {
      using (var kg = kg_layer.GetDatastore())
      {
        var graphQuery = new KnowledgeGraphQueryFilter()
        {
          QueryText = qry
        };
    
        using (var kgRowCursor = kg.SubmitQuery(graphQuery))
        {
          while (await kgRowCursor.WaitForRowsAsync())
          {
            while (kgRowCursor.MoveNext())
            {
              using (var graphRow = kgRowCursor.Current)
              {
                // process the row
                var cnt_val = (int)graphRow.GetCount();
                for (int v = 0; v < cnt_val; v++)
                {
                  var obj_val = graphRow[v] as KnowledgeGraphNamedObjectValue;
                  var type_name = obj_val.GetTypeName();
                  var oid = (long)obj_val.GetObjectID();
                  if (!dict.ContainsKey(type_name))
                  {
                    dict[type_name] = new List<long>();
                  }
                  if (!dict[type_name].Contains(oid))
                    dict[type_name].Add(oid);
                }
              }
            }
          }
        }
        //make an ID Set to create the LinkChart
        var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);
    
        //Create the link chart and show it
        var linkChart = MapFactory.Instance.CreateLinkChart(
                          "KG With ID Set", kg, idSet);
        FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
      }
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.3 or higher.
    See Also