Today I have learned Graph in javascript
Graph in javascript:
In this article, we would be implementing the Graph data structure in JavaScript. The graph is a non-linear data structure. Graph G contains a set of vertices V and a set of Edges E. Graph has lots of applications in computer science.
Graph is basically divided into two broad categories :
- Directed Graph (Di- graph) – Where edges have direction.
- Undirected Graph – Where edges do not represent any directed
There are various ways to represent a Graph:-
- Adjacency Matrix
- Adjacency List
- this.state = {bars: [{ id: 1, x: 20, y: 150, width: 30, height: 100, color: 'blue' },{ id: 2, x: 70, y: 120, width: 30, height: 130, color: 'green' },{ id: 3, x: 120, y: 80, width: 30, height: 170, color: 'red' },],};}render() {return (<div><h1>Bar Chart</h1><svg width="200" height="200">{this.state.bars.map(bar => (<rectkey={bar.id}x={bar.x}y={bar.y}width={bar.width}height={bar.height}fill={bar.color}stroke="black"strokeWidth="2"/>))}</svg></div>);}}
- Output:

Comments
Post a Comment