【发布时间】:2016-03-22 20:48:41
【问题描述】:
在为 highcharts 设置系列方面,我在获取所需内容时遇到了麻烦。我想使用我数据库中的表来发布 y 轴的数字。
所以在我的表中,我有属性,ID、TeamName、TotalWins。
我只有两条记录
ID = 1, TeamName = 波士顿红袜队, TotalWins? = 0 可以为空,因为 MLB 赛季尚未开始
ID = 2, TeamName = 巴尔的摩金莺队, TotalWins? = 0
这是我的图表的ActionResult:
public ActionResult Chart()
{
Highcharts chart = new Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Pie })
.SetTitle(new Title { Text = "Who Has more Wins?" })
.SetSubtitle(new Subtitle { Text = "Source: Sportscenter" })
.SetXAxis(new XAxis
{
Categories = new[] { "Boston Red Sox", "Baltimore Orioles" },
Title = new XAxisTitle { Text = "Teams" }
})
.SetYAxis(new YAxis
{
Min = 0,
Title = new YAxisTitle
{
Text = "Wins (Game)",
Align = AxisTitleAligns.High
}
})
.SetTooltip(new Tooltip { Formatter = "function() { return ''+ this.series.name +': '+ this.y +' millions'; }" })
.SetPlotOptions(new PlotOptions
{
Bar = new PlotOptionsBar
{
DataLabels = new PlotOptionsBarDataLabels { Enabled = true }
}
})
.SetLegend(new Legend
{
Layout = Layouts.Horizontal,
Align = HorizontalAligns.Right,
VerticalAlign = VerticalAligns.Top,
X = -100,
Y = 100,
Floating = true,
BorderWidth = 1,
BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFFFFF")),
Shadow = true
})
.SetCredits(new Credits { Enabled = false })
.SetSeries(new[]
{
new Series { Data = new Data(new object[] { db.Teams.Where(x => x.TeamName == "Boston Red Sox").Count(x => x.TotalWins) /*where the issue is */ }) },
});
return View(chart);
}
不能隐式转换类型'int?' '布尔'
如何设置这个 lambda 表达式,以便它检索波士顿红袜队的总胜场数,然后再检索巴尔的摩金莺队的总胜场数?
【问题讨论】:
标签: c# highcharts lambda