1

我将 HighCharts 安装到我的 MVC 项目中:

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")红色下划线,是唯一指出的错误。我的控制器代码如下。

谁能看到可能导致此错误的原因(演示工作正常 - 但我在 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);
    }

}
}
4

2 回答 2

1

它在您的应用程序中选择了错误的 HighChart 类。

如果您更改以下内容:

Highcharts chart = new Highcharts("chart")

对此:

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

它应该工作。

您必须有另一个具有 bm.Controllers.Highcharts 命名空间的类

于 2013-06-07T13:17:10.957 回答
0

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

使用 DotNet.Highcharts;

那么你可以使用这个:

Highcharts 图表 = 新的 Highcharts("图表")

于 2014-02-16T08:22:23.157 回答