class anychart.charts.Graph Improve this Doc
Extends: anychart.core.Chart
Graph chart class. Learn more about Graph chart
Methods Overview
Specific settings | |
labels() | Getter for graph chart labels. |
layout() | Getter for graph chart layout. |
Data | |
data() | Data settings. |
Elements | |
edges() | Graph chart edges settings getter. |
group() | Getter for chart groups by group id. |
nodes() | Graph chart nodes settings getter. |
Interactivity | |
fit() | Returns chart back to initial view. Reset zoom and translation. |
interactivity() | Getter for graph chart interactivity settings. |
move() | Getter for current chart translation. |
rotation() | Getter for graph chart rotation angle. |
select() | Select settings. |
unselect() | Unselect all selected nodes. |
zoom() | Getter for current zoom factor. |
zoomIn() | Perform zoom in on chart. |
zoomOut() | Perform zoom out on chart. |
Methods Description
data
Getter for the data.
Returns:
Object - Return data object with nodes and edges fields See listing
var data = chart.data(); var nodesData = data.nodes; var edgesData = data.edges; edgesData.set(0, 'stroke', '1 blue'); //Set edge stroke for first edge in dataset nodesData.set(0, 'shape', 'star5'); //Set shape for first node in dataset
Try it:
Setter for the data. Learn more about data
Params:
Name | Type | Description |
---|---|---|
data | Object | Data is object with two required fields 'edges' and 'nodes'.
Requires for node data object:
|
Returns:
anychart.charts.Graph - Self instance for method chaining.edges
Graph chart edges settings getter.
Returns:
anychart.core.graph.elements.Edge - Edges settings instance for method chaining. See listing
var edges = chart.edges(); edges.stroke('1 blue') //set stroke for all edges.
Try it:
Graph chart edges settings setter.
Params:
Name | Type | Description |
---|---|---|
value | Object | Settings object. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
var edgesConfig = {stroke: {thickness: 2, color:'pink, dash: '4 1'}}; chart.edges(edgeConfig); //set stroke for all edges.
Try it:
fit
Returns chart back to initial view. Reset zoom and translation.
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
chart.fit(); //Reset all translation and zoom
Try it:
group
Getter for chart groups by group id.
Detailed description
Use this method you can access only for nodes you pass in data.
You can't access group for nodes other way. Use group method you change almost all available settings you can change in anychart.core.graph.elements.Node class, but only for elements of this group.
You can't access group for nodes other way. Use group method you change almost all available settings you can change in anychart.core.graph.elements.Node class, but only for elements of this group.
Params:
Name | Type | Description |
---|---|---|
id | string | Id of group. |
Returns:
anychart.core.graph.elements.Group | undefined - Group with id set or undefined if group is not found. See listing
var data = { nodes: [{ id: 1, group: 'numbers' }, { id: 2, group: 'numbers' }, { id: 'a', group: 'letters' }], //pass groups for nodes edges: [{ from: 1, to: 2 }] } var chart = anychart.graph(data); var numbers = chart.group('numbers'); var letters = chart.group('letters'); numbers.shape('square') //Set square as shape for all nodes of this group. letters.stroke('1 yellow'); chart.container('container').draw();
Try it:
Configures group by id.
Params:
Name | Type | Description |
---|---|---|
id | string | Id of group. |
value | Object | Group configuration object. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
var data = { nodes: [{ id: 1, group: 'numbers' }, { id: 2, group: 'numbers' }, { id: 'a', group: 'letters' }], //pass groups for nodes edges: [{ from: 1, to: 2 }] } var chart = anychart.graph(data); chart.group('numbers', {fill: 'green', height: 15, shape: 'rectangle', width: 30, height: 15}); chart.group('letters', {fill: 'yellow', height: 10, shape: 'circle', height: 16}); chart.container('container').draw();
Try it:
interactivity
Getter for graph chart interactivity settings.
Returns:
anychart.core.graph.elements.Interactivity - Graph chart interactivity instance for method chaining. See listing
var interactivity = chart.interactivity(); interactivity.nodes(false); //forbid node drag. interactivity.edges(false); //forbid edges interactivity.
Try it:
Setter for graph chart interactivity.
Params:
Name | Type | Description |
---|---|---|
value | Object | Graph chart interactivity settings. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
var interactivityConfig = {enabled:false, nodes:false, edges:false}; chart.interactivity(interactivityConfig); //disable all interactivity.
Try it:
labels
Getter for graph chart labels.
Detailed description
Note Instance of chart labels has lower priority then nodes, edges, and groups labels.
If you disable chart labels but enable nodes labels, nodes for nodes will shown.
If you disable chart labels but enable nodes labels, nodes for nodes will shown.
Returns:
anychart.core.ui.LabelsFactory - LabelsSettings instance. See listing
var labels = chart.labels(); //Change labels settings of all chart elements labels.fontColor('purple'); labels.fontSize(10); var nodesLabels = chart.nodes().labels(); nodesLabels.fontColor(12); //override chart fontSize. Nodes labels has purple fontColor from chart and own fontSize setting.
Try it:
Setter for graph chart labels.
Params:
Name | Type | Description |
---|---|---|
value | Object | string | config object for labels. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
var labelsConfig = {fontFamily: 'Arial', fontSize:14, fontColor: '#000'}; chart.labels(labelsConfig};
Try it:
layout
Getter for graph chart layout.
Returns:
anychart.core.graph.elements.Layout - Graph chart layout settings. See listing
var layoutType = chart.layout();
Try it:
Setter for graph chart layout.
Params:
Name | Type | Description |
---|---|---|
value | Object | string | In object case is chart layout settings, in string case is layout type. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
var data = { nodes: [{ id: 1, x:0, y:0}, {id: 2, x:0, y:50}, { id: 3, x:50, y:25}], edges: [{ from: 1, to: 2 }, { from: 2, to: 3}, { from: 3, to: 1}] } var chart = anychart.graph(data); chart.layout('fixed'); // chart.layout({type: 'fixed"}) this two function call has same result. chart.container('container').draw();
Try it:
move
Getter for current chart translation.
Returns:
Array.<number> - Array with two elements: x and y pixel values of current translation. See listing
var offset = chart.move(); var offsetX = offset[0]; var offsetY = offset[1];
Try it:
Sets chart pixel translation by x and y coordinates.
Params:
Name | Type | Default | Description |
---|---|---|---|
dx | number | 0 | X-coordinate translation. If is null, returns the chart to its initial position. |
dy | number | 0 | Y-coordinate translation. Default is 0. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
chart.move(100,50);
Try it:
nodes
Graph chart nodes settings getter.
Returns:
anychart.core.graph.elements.Node - Nodes settings instance for method chaining. See listing
var nodes = chart.nodes(); nodes.height(25) //Set height for all nodes
Try it:
Graph chart nodes settings setter.
Params:
Name | Type | Description |
---|---|---|
value | Object | Settings object. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
var config = {shape: 'star5', height: 25}; chart.nodes(config);
Try it:
rotation
Getter for graph chart rotation angle.
Returns:
number - Rotation angle, degrees. See listing
var rotationDegree = chart.rotation()
Try it:
Setter for graph chart rotation angle.
Detailed description
It rotate chart from 0 degree not from previous passed.
Params:
Name | Type | Default | Description |
---|---|---|---|
degree | number | 0 | Rotation angle. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
chart.rotation(45); //if you want rotate it on 45 degree more you need pass final angle. chart.rotation(45); // it do nothing chart.rotation(90); // it do what you want
Try it:
select
Selects all nodes.
Returns:
anychart.charts.Graph - Self instance for method chaining.Selects a node by ID.
Params:
Name | Type | Description |
---|---|---|
node_id | string | Id of node to select. |
Returns:
anychart.charts.Graph - Self instance for method chaining.Selects nodes by IDs.
Params:
Name | Type | Description |
---|---|---|
nodes_ids | Array.<string> | The array of node ids to select. |
Returns:
anychart.charts.Graph - Self instance for method chaining.Try it:
unselect
Unselect all selected nodes.
Returns:
anychart.charts.Graph - Self instance for method chaining.Try it:
Deselects selected node by id.
Params:
Name | Type | Description |
---|---|---|
id | string | Id of the node to select. |
Returns:
anychart.charts.Graph - Self instance for method chaining.Deselects selected nodes by ids.
Params:
Name | Type | Description |
---|---|---|
ids | Array.<string> | The array of nodes ids to select. |
Returns:
anychart.charts.Graph - Self instance for method chaining.zoom
Getter for current zoom factor.
Returns:
number - Current zoom factor. See listing
var zoomFactor = chart.zoom(); //Get zoom factor.
Try it:
Setter for current zoom factor.
Params:
Name | Type | Default | Description |
---|---|---|---|
value | number | 1 | Zoom factor. |
cx | number | Scaling point x. | |
cy | number | Scaling point y. |
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
chart.zoom(2); //Increase zoom chart.move(60); //and move chart along x.
zoomIn
Perform zoom in on chart.
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
chart.zoomIn();
Try it:
zoomOut
Perform zoom out on chart.
Returns:
anychart.charts.Graph - Self instance for method chaining. See listing
chart.zoomOut();
Try it: