Asp.net bower安装了plotly.js不起作用

时间:2016-05-30 11:08:15

标签: javascript asp.net bower

我使用bower安装了Plotly.js并在我的视图页面中添加了脚本引用,但是当我运行我的页面时,控制台显示“Uncaught Reference error:Plotly is not defined”

以下是我的设置:

bower.json

{
    "name": "ASP.NET",
    "private": true,
    "dependencies":
    {
        "bootstrap": "3.3.6",
        "jquery": "2.1.4",
        "jquery-validation": "1.15.0",
        "jquery-validation-unobtrusive": "~3.2.6",
        "gl-matrix": "~2.3.2",
        "pixi": "~3.0.11",
        "requirejs": "2.2.0",
        "pixi-particles": "1.6.7",
        "d3": "3.5.17",
        "plotly.js": "~1.12.0"

    },
    "resolutions":
    {
        "jquery": "~2.2.4"
    }
}

带脚本的html页面

@using System.Collections.Generic
@using Microsoft.AspNet.Http
@using Microsoft.AspNet.Authentication
@using WebApplication1.Controllers

@model PitchGraphViewModel

@{
    ViewData["Title"] = "Example Page";
}
<meta charset="utf-8" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<script type="text/javascript" src="~/lib/plotly.js/dist/plotly.js" charset="utf-8"></script>
<!DOCTYPE HTML>
<html>
<head>
    <title>Webgl test page</title>
</head>

<body>
    <canvas id="mycanvas" width="500" height="500"></canvas>
    <div id="tester" style="width:600px;height:250px;"></div>
</body>
</html>
<script>

    var TESTER = document.getElementById('tester');
    Plotly.plot(TESTER, [{
        x: [1, 2, 3, 4, 5],
        y: [1, 2, 4, 8, 16]
    }], {
        margin: { t: 0 }


    });


</script>

plotly.js文件夹结构 plotly.js folder structure

我尝试过needjs shim config作为此页面,但它失败了: Using RequireJS to load plotly and D3

我检查了plotly.js是使用浏览器开发工具在页面访问时下载的,但'Plotly'仍未定义。

1 个答案:

答案 0 :(得分:0)

它通过从布局页面中删除Requirejs脚本引用来解决。我仍然不知道为什么会这样。也许冲突?