1

我正在关注一个教程how-to-use-highcharts-js-with-asp-net-mvc-4

当我构建应用程序时,我收到错误

找不到类型或命名空间名称“DotNet”(您是否缺少 using 指令或程序集引用?)

我有我的控制器

using HighChart.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Highcharts;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using DotNet.Highcharts.Enums;

在此 DotNet 下方有一个蓝色波浪线。以及我的参考文件夹中的参考“DotNet.Highcharts”。

我正在使用 VS 2012 Professional(如果重要的话)

我是否需要在我的 webconfig 中添加一些我缺少的东西,或者我是否需要设置参考路径?我以前使用过 nuget 包,没有遇到过这个问题,所以不确定我需要做什么。

我做了什么。

  • 重启VS
  • 关闭/重新打开项目
  • 从头开始项目(mvc 4 为空)并从 nuget 添加 DotNet.Highcharts 和 Jquery 包,并按照我上面列出的教程进行操作。

模型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

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

控制器

using HighChart.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Highcharts;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using DotNet.Highcharts.Enums;

namespace HighChart.Controllers
{
    public class ChartSampleController : Controller
    {
        //
        // GET: /ChartSample/

        public ActionResult Index()
        {
            var transactionCounts = new List<TransactionCount> {
            new TransactionCount() { MonthName="January", Count=30},
            new TransactionCount() { MonthName="February", Count=40},
            new TransactionCount() { MonthName="March", Count=4},
            new TransactionCount() { MonthName="April", Count=35}
            };

            var xDataMonths = transactionCounts.Select(i => i.MonthName).ToArray();
            var yDataCounts = transactionCounts.Select(i => new object[] { i.Count }).ToArray();


            //instanciate an object o the highcharts 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 lable 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 the Y values
            .SetSeries(new[]
            {
                new Series {Name = "Hour", Data = new Data(yDataCounts)},
                //you can add more y data to create a second line
                // new series { Name = "Other Name", Data = new Data(OtherData)}
            });
            return View(chart);
            //return View();
        }
    }
}

看法

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="~/Scripts/jquery-2.1.3.min.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts.js"></script>
</head>
<body>
    <div>
        @model DotNet.Highcharts.Highcharts
        <p>My Chart</p>
        @(Model)
    </div>
</body>
</html>

任何帮助将不胜感激!提前致谢

4

2 回答 2

0

您是否将 dll 添加到引用中?您需要通过浏览到 dll 位置手动执行此操作。

于 2015-04-28T03:26:17.820 回答
0

就我而言,我必须专门下载“Net 4.0”DLL。 https://dotnethighcharts.codeplex.com/releases/view/121251

老实说,我认为nuget包会解决这个问题

于 2015-05-14T21:45:09.763 回答