我正在使用Visual Studio 2012 / ASP.NET MVC 4创建一个网站,我想使用Flot在首页上放置一个图表。
项目的BundleConfig设置为包含整个Flot目录,并包含jQuery:
bundles.Add(new ScriptBundle("~/bundles/flot").IncludeDirectory("~/Scripts/flot", "*.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
脚本在_Layout.cshtml文件中呈现。
@Scripts.Render("~/bundles/modernizr", "~/bundles/jquery", "~bundles/flot")
脚本在主页的视图上再次呈现,并且flotcontainer div显示在主页上,但仅显示为空白矩形。
@{
ViewBag.Title = "Home Page";
Scripts.Render("~/bundles/modernizr", "~/bundles/jquery", "~bundles/flot");
}
<div id="flotcontainer" style="width: 600px; height: 400px;"></div>
<script type="text/javascript">
$(function () {
var oilPrices = [[1167692400000, 61.05] ...
...(Flot chart example goes here, nothing wrong with this part)...
});
</script>
答案 0 :(得分:0)
Mark's answer证明是正确的 - 问题是&#34; ~bundles / flot&#34;错过了一个反斜杠,它应该写成&#34;〜/ bundles / flot&#34;。谢谢Mark!