highcharts使用mvc从数据库中使用数据的示例

时间:2012-11-08 14:38:56

标签: asp.net-mvc highcharts

有没有人有一个简单的例子,使用DotNet.Highcarts在MS SQL DB中填充数据?

我有使用静态数据的演示

Highcharts chart = new Highcharts("chart")
        .SetCredits(new Credits { Enabled = false })
        .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
        .SetTitle(new Title { Text = "Membership Overview" })
        .SetXAxis(new XAxis { Categories = new[] { "Paid Members", "Active Members", "Retained Members", "New Members", "Lapsed Members" } })
        .SetYAxis(new YAxis
        {
            Min = 0,
            Title = new YAxisTitle { Text = "Total Members" }
        })
        .SetTooltip(new Tooltip { Formatter = "function() { return ''+ this.series.name +': '+ this.y +''; }" })
        .SetPlotOptions(new PlotOptions { Bar = new PlotOptionsBar { Stacking = Stackings.Normal } })
        .SetSeries(new[]
                   {
                       new Series { Name = "Total", Data = new Data(new object[] { 441, 441, 22, 30, 610 }) }
                    });

如何更改系列以接受来自我的数据库的数据?

假设我需要像这样连接到DB:

var newcustomer = db.Customer;

然后做这样的事情:

new Series
{
    Name = "Total",
    Data = new Data(newcustomer.Select(x => ............

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:4)

对于其他有类似问题的人......

var paidmembers = (from c in db.Customer
                   where c.CustomerStatusID == 1
                   select c).Count();

var activemembers = (from c in db.Customer
                     where c.CustomerStatusID == 2
                     select c).Count();

new Series {
            Name = "Category",
            Data = new Data(new object[] {paidmembers, activemembers})
}