require(["esri/Graphic"], function(Graphic) { /* code goes here */ });
Class: esri/Graphic
Inheritance: Graphic Accessor
Since: ArcGIS API for JavaScript 4.0

A Graphic is a vector representation of real world geographic phenomena. It can contain geometry, a symbol, and attributes. A Graphic is displayed in the GraphicsLayer.

To learn how to work with graphics, see the Intro to graphics tutorial.

var polyline = {
  type: "polyline",  // autocasts as new Polyline()
    paths: [
      [-111.30, 52.68],
      [-98, 49.5],
      [-93.94, 29.89]
    ]
};

var polylineSymbol = {
  type: "simple-line",  // autocasts as SimpleLineSymbol()
  color: [226, 119, 40],
  width: 4
};

var polylineAtt = {
  Name: "Keystone Pipeline",
  Owner: "TransCanada"
};

var polylineGraphic = new Graphic({
  geometry: polyline,
  symbol: polylineSymbol,
  attributes: polylineAtt
});

view.graphics.add(polylineGraphic);
See also:

Constructors

new Graphic(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
Object

Name-value pairs of fields and field values associated with the graphic.

more details
more detailsGraphic
String

The name of the class.

more details
more detailsAccessor
Geometry

The geometry that defines the graphic's location.

more details
more detailsGraphic
Layer

If applicable, references the layer in which the graphic is stored.

more details
more detailsGraphic
PopupTemplate

The template for displaying content in a Popup when the graphic is selected.

more details
more detailsGraphic
Symbol

The Symbol for the graphic.

more details
more detailsGraphic
Boolean

Indicates the visibility of the graphic.

more details
more detailsGraphic

Property Details

attributesObject

Name-value pairs of fields and field values associated with the graphic.

Example:
var graphic = new Graphic();
graphic.attributes = {
  "name": "Spruce",
  "family": "Pinaceae",
  "count": 126
};
declaredClassStringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

The geometry that defines the graphic's location.

Z-values defined in a geographic or metric coordinate system are expressed in meters. However, in local scenes that use a projected coordinate system, vertical units are assumed to be the same as the horizontal units specified by the service.

Example:
// First create a point geometry
var point = {
  type: "point",  // autocasts as new Point()
  longitude: -71.2643,
  latitude: 42.0909
};

// Create a symbol for drawing the point
var markerSymbol = {
  type: "simple-marker",  // autocasts as new SimpleMarkerSymbol()
  color: [226, 119, 40]
};

// Create a graphic and add the geometry and symbol to it
var pointGraphic = new Graphic({
  geometry: point,
  symbol: markerSymbol
});
layerLayer

If applicable, references the layer in which the graphic is stored.

The template for displaying content in a Popup when the graphic is selected. The PopupTemplate may be used to access a graphic's attributes and display their values in the view's default popup. See the documentation for PopupTemplate for details on how to display attribute values in the popup.

As of 4.8 to get the actual popupTemplate of the graphic, see the getEffectivePopupTemplate() method that either returns this value or the popupTemplate of the graphic's layer.

See also:

The Symbol for the graphic. Choosing a symbol for a graphic depends on the View type (SceneView or MapView), and the geometry type of the graphic.

Each graphic may have its own symbol specified when the parent layer is a GraphicsLayer. For a FeatureLayer the symbol of each graphic should not be set by the developer since the graphics' rendering properties are determined by the layer's renderer.

Example:
view.on("click", function(event){
  var graphic = new Graphic({
    geometry: event.mapPoint,
    symbol: {
      type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
      color: "blue",
      size: 8,
      outline: { // autocasts as new SimpleLineSymbol()
        width: 0.5,
        color: "darkblue"
      }
    }
  });
});
visibleBoolean

Indicates the visibility of the graphic.

Default Value:true

Method Overview

NameReturn TypeSummaryClass
Graphic

Creates a deep clone of the graphic object.

more details
more detailsGraphic
*

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform.

more details
more detailsGraphic
*

Returns the value of the specified attribute.

more details
more detailsGraphic
PopupTemplate

Returns the popup template applicable for the graphic.

more details
more detailsGraphic

Sets a new value to the specified attribute.

more details
more detailsGraphic
Object

Converts an instance of this class to its ArcGIS portal JSON representation.

more details
more detailsGraphic

Method Details

clone(){Graphic}

Creates a deep clone of the graphic object.

Returns:
TypeDescription
GraphicReturns a deep clone of the graphic.
fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter:
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns:
TypeDescription
*Returns a new instance of this class.
getAttribute(name){*}

Returns the value of the specified attribute.

Parameter:
name String

The name of the attribute.

Returns:
TypeDescription
*Returns the value of the attribute specified by name.
getEffectivePopupTemplate(){PopupTemplate}
Since: ArcGIS API for JavaScript 4.8

Returns the popup template applicable for the graphic. It's either the value of popupTemplate or the popupTemplate from the graphic's layer.

Returns:
TypeDescription
PopupTemplateReturns the popup template of the graphic.
setAttribute(name, newValue)

Sets a new value to the specified attribute.

Parameters:
name String

The name of the attribute to set.

newValue *

The new value to set on the named attribute.

toJSON(){Object}

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() topic in the Guide for more information.

Returns:
TypeDescription
ObjectThe ArcGIS portal JSON representation of an instance of this class.

API Reference search results

NameTypeModule
Loading...