Hello everyone,
I apologize for my English, but I've encountered an issue with my project. I'm trying to visualize my database, and while my console returns the correct data types and they are well-stocked, I'm unable to display a graph on my webpage. It would be incredible if you could help me with this! (i use angular )
Thank you!
service: import { visu } from './visu/visu.component';
import { Injectable } from 'Aangular/core';
import * as neo4j from 'neo4j-driver';
AInjectable({
providedIn: 'root'
})
export class Neo4jService {
driver: any;
constructor() {
this.driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'Password'));
}
getDriver() {
return this.driver;
};
}
visu.component:
// TypeScript
import {
Component,
OnInit,
AfterViewInit,
ElementRef,
ViewChild,
} from '@angular/core';
import { FormsModule } from 'Aangular/forms';
import { CommonModule } from 'Aangular/common';
import { Neo4jService } from '../service';
import { DataSet, Network } from 'vis-network/standalone/esm/vis-network';
AComponent({
selector: 'app-visu',
templateUrl: './visu.component.html',
styleUrls: ['./visu.component.scss'],
standalone: true,
imports: [FormsModule, CommonModule],
})
export class visu implements OnInit, AfterViewInit {
AViewChild('mynetwork', { static: false }) networkContainer!: ElementRef;
command = '';
neoResults: any;
driver: any;
data: any;
network: any;
constructor(private service: Neo4jService) {
this.driver = this.service.getDriver();
}
ngOnInit() {
let session = this.driver.session();
// Utilisez la session pour exécuter des commandes Cypher...
console.log(this.data)
}
ngAfterViewInit() {
this.network = new Network(
this.networkContainer.nativeElement,
this.data,
{}
);
console.log('network after init:', this.network);
}
executeCypherCommand() {
let session = this.driver.session();
session.run(this.command).then((result: { records: any }) => {
this.neoResults = result.records;
console.log(this.neoResults);
window.localStorage.setItem('data', JSON.stringify(this.neoResults));
session.close();
// Préparez les nouvelles données pour le graphique.
let nodes = new DataSet<any>([]);
let edges = new DataSet<any>([]);
this.neoResults.forEach((record: any) => {
// Ajoutez vos nœuds et vos arêtes ici.
});
this.data = {
nodes: nodes,
edges: edges,
};
// Mettez à jour le graphique.
if (this.network) {
console.log('data: ', this.data)
this.network.setData(this.data);
console.log('network after setData:', this.network);
} else {
console.log('network is undefined!');
}
});
}
}
visu.html :
<input [(ngModel)]="command" placeholder="Enter Cypher command">
<button (click)="executeCypherCommand()">Execute
Neo4j Graph
MATCH (p:Person)-[r:OWNS]->(a:Animal) RETURN p, r, a
Thanks to the one who will help me (can't put @ the forum think i tag someone so i put a A )