DotNet HighChart 未填充

DotNet HighChart not populating

我是 MVC 新手,第一次尝试使用 DotNet High Chart。我正在关注 Visual Studios MVC 5 中的 this 教程。

我的捆绑包:

public class BundleConfig
{

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));


        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));

        bundles.Add(new Bundle("~/bundles/highchart").Include(
                    "~/Scripts/Highcharts-4.0.1/js/highchart.js"));
    }
}

}

我的模特:

namespace Charts2.Models
{
public class TransactionCount
{
    public string MonthName { get; set; }
    public int Count { get; set; }
}
}

我的控制器:

namespace Charts2.Controllers
{
     public class ChartSampleController : Controller
{
    // GET: ChartSample
    public ActionResult Index()
    {
        //create a collection of data
        var transactionCounts = new List<TransactionCount>{
                        new TransactionCount(){ MonthName="January", Count=30},
                        new TransactionCount(){ MonthName="Febuary", Count=40},
                        new TransactionCount(){ MonthName="March", Count=4},
                        new TransactionCount(){ MonthName="April", Count=35},
        };

        // modify data type to make it of array types
        var xDataMonths = transactionCounts.Select(i => i.MonthName).ToArray();
        var yDataCounts = transactionCounts.Select(i => new object[] { i.Count }).ToArray();

        //instanciate an object of the high charts type
        var chart = new Highcharts("chart")
                // define the type of chart
                .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line})
                //overall title of the chart
                .SetTitle(new Title { Text = "Incoming Transactions per hour"})
                //small label below the main title
                .SetSubtitle(new Subtitle { Text = "Accounting"})
                // load the x values
                .SetXAxis(new XAxis {Categories = xDataMonths})
                // set the y title
                .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Number of Transactions"}})
                    .SetTooltip(new Tooltip{
                        Enabled = true,
                        Formatter = @"function() { return '<b>'+this.series.name +'</b><br/>'+this.x+': '+this.y;}"
                        })
                        .SetPlotOptions(new PlotOptions{
                        Line = new PlotOptionsLine {
                        DataLabels = new PlotOptionsLineDataLabels {
                        Enabled = true
                    },
                    EnableMouseTracking = false
                        } 
                  })
                     //load y values
.SetSeries(new []
    {
    new Series {Name = "Hour", Data = new Data(yDataCounts)},

});


        return View(chart);
    }
}
}

我的观点:

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

@model DotNet.Highcharts.Highcharts

<p> My Chart </p>
@(Model)

我的分享_Index:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/highchart")

</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
            </ul>
            @Html.Partial("_LoginPartial")
        </div>
    </div>
</div>
<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
    </footer>
</div>


@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

每当我 运行 应用程序时,图表根本不会生成。我已经按照教程进行操作,但无法理解我哪里出错了。在控制台上,我收到以下异常:

Uncaught ReferenceError: Highcharts is not defined

如有任何建议,我们将不胜感激 谢谢

请问 post 整个视图代码。在您当前的视图中,您没有添加要查看的高图表包 像

这样的东西
@Scripts.Render("~/bundles/highchart")

我已经意识到我哪里出错了。我在包名称末尾缺少一个 s,我更改了包:

bundles.Add(new ScriptBundle("~/bundles/highcharts").Include(
             "~/Scripts/Highcharts-4.0.1/js/highcharts.js"
                ));

并更新了 _index,现在可以使用了。