0

我正在使用 arbor.js 创建一个力导向图。以下是我的一些代码:

文件.aspx:

<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="file.aspx.cs" Inherits="file.Views.afile.RelationalMap" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en" >
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>My Relational Map Generator</title>
  <script type="text/javascript" src="../../Scripts/jquery-1.6.1.min.js"></script>
  <script src="../../Scripts/jquery.address-1.4.min.js"></script>

  <script type="text/javascript" src="../../Scripts/arbor.js"></script>
  <script type="text/javascript" src="../../Scripts/arbor-tween.js"></script>
  <script type="text/javascript" src="../../Scripts/arbor-graphics.js"></script>

  <script type="text/javascript" src="../../Scripts/renderer.js"></script>
</head>
<body bgcolor="white">
  <image src="../../images/armg.png" height=40px></image>
  <div align="center" height="100%" width="100%">
  <canvas id="sitemap" width="1360" height="349"></canvas>
  </div>
    </body>
</html>

文件.cs:

...
...
...
GenJS = GenJS +
                    "var sys = arbor.ParticleSystem();" +
                    "sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015});" +
                    "sys.renderer = Renderer(\"#sitemap\");" +
                    "sys.graft(theUI) </script>";

ClientScript.RegisterClientScriptBlock(GetType(), "JavaScript", GenJS);

“GenJS”是一个包含脚本标签的字符串,上面的只是它的一部分。

当我运行它时,什么都没有发生。

我认为这与 render.js 库有关。但是,当我尝试在单独的 HTML 文件或独立的 html 文件中执行此操作时,它正在工作。

请帮我解决一下这个。

4

1 回答 1

0

我设法自己解决了。

我只是替换这个:

GenJS = GenJS +
                    "var sys = arbor.ParticleSystem();" +
                    "sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015});" +
                    "sys.renderer = Renderer(\"#sitemap\");" +
                    "sys.graft(theUI) </script>";

ClientScript.RegisterClientScriptBlock(GetType(), "JavaScript", GenJS);

                Response.Write(contHTML);

有了这个:

string contHTML = "<!DOCTYPE html PUBLIC \" -//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">" +
                              "<html lang=\"en\" >" +
                              "<head>" +
                              "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" +
                              "<title>A Prime Relational Map Generator</title>" +
                              "</head>" +
                              "<body bgcolor=\"white\">" +
                              "<image src=\"../../images/armg.png\" height=40px></image>" +
                              "<div align=\"center\" height=\"100%\" width=\"100%\">" +
                              "<canvas id=\"sitemap\" width=\"1360\" height=\"349\"></canvas>" +
                              "</div>" +
                              "<script type=\"text/javascript\" src=\"../../Scripts/jquery-1.6.1.min.js\"></script>" +
                              "<script type=\"text/javascript\" src=\"../../Scripts/jquery.address-1.4.min.js\"></script>" +
                              "<script type=\"text/javascript\" src=\"../../Scripts/arbor.js\"></script>" +
                              "<script type=\"text/javascript\" src=\"../../Scripts/arbor-tween.js\"></script>" +
                              "<script type=\"text/javascript\" src=\"../../Scripts/arbor-graphics.js\"></script>" +
                              "<script type=\"text/javascript\" src=\"../../Scripts/renderer.js\"></script>" +
                              GenJS +
                              "</body>" +
                              "</html>";

            Response.Write(contHTML);

感谢所有花时间阅读我帖子的人。

于 2013-06-27T06:54:40.240 回答