JavaScript 未按预期工作

发布于 2024-12-09 09:51:04 字数 862 浏览 5 评论 0原文

我想在我的 VC++ 程序中绘制漂亮的图表,因此决定通过 HTML 和 JavaScript 来实现。

如图所示,我下载了一个 Javascript 库并按照其网站中所述使用它。
如何使用?

下载 raphael.js 并将其包含到您的 HTML 页面中,然后使用它,如下简单:

// Creates canvas 320 × 200 at 10, 50
var paper = Raphael(10, 50, 320, 200);

// Creates circle at x = 50, y = 40, with radius 10
var circle = paper.circle(50, 40, 10);

// Sets the fill attribute of the circle to red (#f00)
circle.attr("fill", "#f00");

// Sets the stroke attribute of the circle to white    
circle.attr("stroke", "#fff");

我包含了如下所示的 javascript 文件:

<head>
<script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript">
ABOVE CODE
</script>

如果您尝试使用它,它将无法工作。我试图让它发挥作用,但失败了。我有一个问题。我怎样才能在不复制演示的另存为页面中的内容的情况下工作?当然,它包括文档,但它是参考。

它如何简单地工作?谢谢!

I want to draw chart that is beautiful in my VC++ program and so decided to implement in by HTML and JavaScript.

As it show, I downloaded a Javascript lib and used it as it said in its site.
How to use it?

Download and include raphael.js into your HTML page, then use it as simple as:

// Creates canvas 320 × 200 at 10, 50
var paper = Raphael(10, 50, 320, 200);

// Creates circle at x = 50, y = 40, with radius 10
var circle = paper.circle(50, 40, 10);

// Sets the fill attribute of the circle to red (#f00)
circle.attr("fill", "#f00");

// Sets the stroke attribute of the circle to white    
circle.attr("stroke", "#fff");

I included javascript file like below:

<head>
<script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript">
ABOVE CODE
</script>

If you try it, it won't work. I tried to make it work, but could not. I have a question. How can I do it work without copying things from save as page of their demo? Of course, it includes documentation, but it is reference.

How does it work simply? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窝囊感情。 2024-12-16 09:51:04

检查对 Raphael 库的引用,然后尝试以下代码:

<head>
  <script type='text/javascript' src='raphael.js'></script>

  <script type='text/javascript'>
  //<![CDATA[ 
  window.onload=function(){
    // Creates canvas 320 × 200 at 10, 50
    var paper = Raphael(10, 50, 320, 200);

    // Creates circle at x = 50, y = 40, with radius 10
    var circle = paper.circle(50, 40, 10);
    // Sets the fill attribute of the circle to red (#f00)
    circle.attr("fill", "#f00");

    // Sets the stroke attribute of the circle to white    
    circle.attr("stroke", "#fff");
  }
  //]]> 
  </script>
</head>

这对我有用,请确保您的引用良好。

JSFiddle

Check the reference to the Raphael library, and then try this code:

<head>
  <script type='text/javascript' src='raphael.js'></script>

  <script type='text/javascript'>
  //<![CDATA[ 
  window.onload=function(){
    // Creates canvas 320 × 200 at 10, 50
    var paper = Raphael(10, 50, 320, 200);

    // Creates circle at x = 50, y = 40, with radius 10
    var circle = paper.circle(50, 40, 10);
    // Sets the fill attribute of the circle to red (#f00)
    circle.attr("fill", "#f00");

    // Sets the stroke attribute of the circle to white    
    circle.attr("stroke", "#fff");
  }
  //]]> 
  </script>
</head>

This works for me, make sure your reference is good.

JSFiddle

梦里的微风 2024-12-16 09:51:04
  • 拉斐尔联系正确吗? (查看源代码,然后按 raphael.js 链接 - 它有效吗?)
  • 尝试使用 参考。您的代码应该在整个屏幕上绘制。
  • 您是否看到页面中创建了新元素?为此使用萤火虫。
  • 您使用的是哪个版本的 Raphael?最近它升级到了版本2。
  • Is Raphael linked properly? (view source then press the raphael.js link - does it work?)
  • Try to use examples from the reference. Your code should paint across the entire screen.
  • Do you see a new element created in the page? use firebug for this.
  • Which version of Raphael are you using? Recently it was upgraded to version 2.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文