HighCharts不包含在ASP.Net MVC C#中带1个参数的构造函数

时间:2013-06-07 12:46:38

标签: c# asp.net asp.net-mvc highcharts

我在我的MVC项目中安装了HighCharts:

Install-Package DotNet.HighCharts

...并试图运行一个基本的饼图演示。但是,我在VS2012Express中收到一条消息:

bm.Controllers.Highcharts' does not contain a constructor that takes 1 arguments

它不喜欢的行是:Highcharts chart = new Highcharts("chart")

new Highcharts("chart")在Red中加下划线,是唯一记错的错误。我的控制器代码如下。

任何人都可以看到whay可能导致此错误(演示工作正常 - 但我在web.config文件等中看不到任何不同?

谢谢,

标记

using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Drawing;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Samples.Models;
using Point = DotNet.Highcharts.Options.Point;


namespace bm.Controllers
{
public class ChartController : Controller
{
    //
    // GET: /Chart/

    public ActionResult Index()
    {

        return View();
    }

    public ActionResult DataLabels()
    {
        string[] categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
        object[] tokioData = new object[] { 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 };
        object[] londonData = new object[] { 3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8 };

        Highcharts chart = new Highcharts("chart")
            .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
            .SetTitle(new Title { Text = "Monthly Average Temperature" })
            .SetSubtitle(new Subtitle { Text = "Source: WorldClimate.com" })
            .SetXAxis(new XAxis { Categories = categories })
            .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Temperature (°C)" } })
            .SetTooltip(new Tooltip { Enabled = true, Formatter = @"function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +'°C'; }" })
            .SetPlotOptions(new PlotOptions
            {
                Line = new PlotOptionsLine
                {
                    DataLabels = new PlotOptionsLineDataLabels
                    {
                        Enabled = true
                    },
                    EnableMouseTracking = false
                }
            })
            .SetSeries(new[]
                       {
                           new Series { Name = "Tokyo", Data = new Data(tokioData) },
                           new Series { Name = "London", Data = new Data(londonData) }
                       });

        return View(chart);
    }

}
}

2 个答案:

答案 0 :(得分:1)

它正在你的应用程序中找到错误的HighChart类。

如果您更改以下内容:

Highcharts chart = new Highcharts("chart")

对此:

DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")

它应该有用。

您必须拥有另一个名为bm.Controllers.Highcharts

的类

答案 1 :(得分:0)

将以下dll添加到您的代码中:

  

使用DotNet.Highcharts;

然后你可以使用它:

  

Highcharts chart = new Highcharts(“chart”)