加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 如何使用dotnet highcharts dll在MVC3中显示Hi

发布时间:2020-12-16 03:22:04 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试一种方法将数据绑定到饼图 Public ActionResult Charts { Highcharts chart = new Highcharts("chart") .InitChart(new Chart { PlotShadow = false }) .SetTitle(new Title { Text = "Browser market shares at a specific website,2010" }) .Set
我正在尝试一种方法将数据绑定到饼图

Public ActionResult Charts
  {
      Highcharts chart = new Highcharts("chart")
        .InitChart(new Chart { PlotShadow = false })
        .SetTitle(new Title { Text = "Browser market shares at a specific website,2010" })
        .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" })
        .SetPlotOptions(new PlotOptions
        {
            Pie = new PlotOptionsPie
            {
                AllowPointSelect = true,Cursor = Cursors.Pointer,DataLabels = new PlotOptionsPieDataLabels
                {
                    Color = ColorTranslator.FromHtml("#000000"),ConnectorColor = ColorTranslator.FromHtml("#000000"),Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }"
                }
            }
        })
        .SetSeries(new Series
        {
            Type = ChartTypes.Pie,Name = "Browser share",Data = new Data(new object[]
                                   {
                                       new object[] { "Firefox",45.0 },new object[] { "IE",26.8 },new DotNet.Highcharts.Options.Point
                                       {
                                           Name = "Chrome",Y = 12.8,Sliced = true,Selected = true
                                       },new object[] { "Safari",8.5 },new object[] { "Opera",6.2 },new object[] { "Others",0.7 }
                                   })
                             });
        }
    }

    public JsonResult GetData()
    {
        int Param1;
        Param1 = 1;     
        var reports = db.ExecuteStoreQuery<ResourceReports>("ResourceReports @EmployeeID",new SqlParameter("@EmployeeID",Param1)).ToList();
        return Json(reports,JsonRequestBehavior.AllowGet);
    }

我想替换

.SetSeries(new Series
    {
        Type = ChartTypes.Pie,0.7 }
                                   })
        });
    }

使用我的GetData()我该怎么做,.SetSeries中的数据应该是我在GetData方法中返回的数据

解决方法

看来你正在使用Dotnet.Highcharts.您可以创建一个Series列表和一个Point列表.

List<Series> mySeries = new List<Series>();
List<Point> myPoints = new List<Point>();

我会遍历你需要创建的每个系列并生成点数据,如下所示:

myPoints.Add(new Point {
    X = (detailRec.RecordTime - new DateTime(1970,1,0)).TotalMilliseconds,Y = detailRec.TotalCount
});

然后你可以使用它的数据点列表创建系列本身,如下所示:

mySeries.Add(new Series{
  Name = distinctDistrict.Name,Data = new Data(myPoints.ToArray())
});

然后要设置Series,您可以使用以下语句:

.SetSeries(mySeries.Select(s => new Series { 
  Name = s.Name,Data = s.Data 
}).ToArray())

如果在Visual Studio中使用对象浏览器,则可以看到Series和Point类的其他属性和方法.要使用上面的代码,您必须包含以下using语句:

using DotNet.Highcharts;
using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using Point = DotNet.Highcharts.Options.Point;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读