DotNet.Highcharts包问题

时间:2015-02-25 17:56:39

标签: asp.net-mvc-4 dotnethighcharts

我正在关注教程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专业版(如果重要的话)

我是否需要在我的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>

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

在我的情况下,我不得不专门下载“Net 4.0”DLL。 https://dotnethighcharts.codeplex.com/releases/view/121251

老实说,我认为nuget包会处理这个