在ASP中,HighCharts不包含接受1个参数的构造函数.Net MVC c#

本文关键字:参数 构造函数 Net MVC 1个 ASP HighCharts 包含接 | 更新日期: 2023-09-27 18:17:19

我将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")用红色下划线,这是注意到的唯一错误。我的控制器代码如下:

有人能看到是什么可能导致这个错误(演示工作很好-但我不能看到任何不同的网络。配置文件等?

谢谢你,

标记
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);
    }
}
}

在ASP中,HighCharts不包含接受1个参数的构造函数.Net MVC c#

在你的应用程序中选取了错误的HighChart类。

如果您更改以下内容:

Highcharts chart = new Highcharts("chart")

:

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

应该可以。

必须有一个命名空间为bm.Controllers.Highcharts的类

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

使用DotNet.Highcharts;

那么你可以这样写:

Highcharts chart = new Highcharts("chart")