私は d3.js を試してきました。たとえば、強制指向グラフには次のサンプル コードがあります。
d3.json("file.json", function (error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
私はasp.net MVCを使用しているので、次のようなActionResultでjsonファイルを作成しようとしました:
[HttpGet]
public ActionResult visualizationdata()
{
FileInfo file= new FileInfo(Path.Combine( HostingEnvironment.ApplicationPhysicalPath , @"Content\visualizationdata.json"));
return File(file.Open(FileMode.Open, FileAccess.Read), "application/json", "visualizationdata.json");
}
私が持っているd3の例を含む私のcshtml内:
d3.json("@Url.Action("visualizationdata")" //the rest of the example code in d3.js
json ファイルの内容は次のとおりです。
{
"nodes":[
{"name":"1","group":1},
{"name":"2","group":1},
//just json format (but no variable receiving it)
「/controller/visualizationdata」として get リクエストを送信すると、ファイルは正常にレンダリングされます
解決策:stackoverflowの仲間によって提供されます
バージョンを 2 から 3 に変更するだけです: http://d3js.org/d3.v3.min.js