ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapFactory Class / CreateLinkChart Method / CreateLinkChart(String,Uri,KnowledgeGraphLayerIDSet,String) Method
The name of the map.
A Uri link to a knowledge graph service.
A set of Named Object types and record ids that sets the content of the Knowledge Graph layer. See KnowledgeGraphLayerIDSet.
The path to a link chart to use as a template for layout and styling. Use null or an empty string to create the link chart with the default layout and styling. If specified, the template link chart must use the same knowledge graph service as knowledgeGraphServiceUri.
Example

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

    Parameters

    name
    The name of the map.
    knowledgeGraphServiceUri
    A Uri link to a knowledge graph service.
    idSet
    A set of Named Object types and record ids that sets the content of the Knowledge Graph layer. See KnowledgeGraphLayerIDSet.
    templateLinkChartPath
    The path to a link chart to use as a template for layout and styling. Use null or an empty string to create the link chart with the default layout and styling. If specified, the template link chart must use the same knowledge graph service as knowledgeGraphServiceUri.

    Return Value

    A map of type MapType.LinkChart.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    knowledgeGraphServiceUri cannot be null.
    templateLinkChartPath either does not exist in the current project, is not a Link Chart, does not contain a Knowledge Graph layer or does not contain the same Knowledge Graph service as knowledgeGraphServiceUri.
    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 based on a template link chart
    // note that the template link chart MUST use the same KG server
    
    string url =
            @"https://acme.server.com/server/rest/services/Hosted/AcmeKnowledgeGraph/KnowledgeGraphServer";
    
    QueuedTask.Run(() =>
    {
      // find the existing link chart by name
      var projectItem = Project.Current.GetItems<MapProjectItem>()
      .FirstOrDefault(pi => pi.Name == "Acme Link Chart");
      var linkChartMap = projectItem?.GetMap();
      if (linkChartMap == null)
        return;
    
      //Create a connection properties
      var kg_props =
          new KnowledgeGraphConnectionProperties(new Uri(url));
      try
      {
        //Open a connection
        using (var kg = new KnowledgeGraph(kg_props))
        {
          //Add all entities to the link chart
          var idSet = KnowledgeGraphLayerIDSet.FromKnowledgeGraph(
                kg, KnowledgeGraphFilterType.AllEntities);
          //Create the new link chart and show it
          var newLinkChart = MapFactory.Instance.CreateLinkChart(
                            "KG from Template", kg, idSet, linkChartMap.URI);
          FrameworkApplication.Panes.CreateMapPaneAsync(newLinkChart);
        }
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
      }
    });
    
    
    
    Checking KnowledgeGraphLayerException
    // running on QueuedTask
    
    var dict = new Dictionary<string, List<long>>();
    dict.Add("person", new List<long>());  //Empty list means all records
    dict.Add("made_call", null);  //null list means all records
    
    // or specific records - however the ids are obtained
    dict.Add("phone_call", new List<long>() { 1, 5, 18, 36, 78 });
    
    // make the id set
    var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);
    
    try
    {
      //Create the link chart and show it
      var linkChart = MapFactory.Instance.CreateLinkChart(
                        "KG With ID Set", kg, idSet);
      FrameworkApplication.Panes.CreateMapPaneAsync(linkChart);
    }
    catch (KnowledgeGraphLayerException e)
    {
      // get the invalid named types
      //   remember that the named types are case-sensitive
      var invalidNamedTypes = e.InvalidNamedTypes;
    
      // do something with the invalid named types 
      // for example - log or return to caller to show message to user
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.3 or higher.
    See Also