我正在尝试从我的数据库填充高图表线图。
我的约会模式:
[Display(Name = "Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime Date { get; set; }
[Display(Name = "Left IOP")]
public int IOPLeft { get; set; }
[ForeignKey("Patient")]
public Guid PatientId { get; set; }
public virtual Patient Patient { get; set; }
我创建了以下控制器:
public ActionResult IOPLeftChart(Guid? id) //
{
var dataLeft = (from d in db.Appointments
where d.PatientId == id
select new
{
Date = d.Date,
IOPLeft = d.IOPLeft,
}).ToList();
var xSeries = dataLeft.Select(a => a.Date.ToString("dd/MM/yyyy")).ToArray();
var ySeries = dataLeft.Select(a => new object[]{a.IOPLeft}).ToArray();
// instantiate an object of the high charts type
var chart = new Highcharts("chart")
// define the type of chart
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
//overall title of the chart
.SetTitle(new Title { Text = "Left IOP" })
//small label below the main title
.SetSubtitle(new Subtitle { Text = "LeftIOP" })
// load the x values
.SetXAxis(new XAxis { Categories = xSeries })
// set the y title
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "IOP" } })
.SetTooltip(new Tooltip
{
Enabled = true,
Formatter = @"function() { return '<b>'+this.series.name +'</b><br/>'+this.x+': '+this.y;}"
})
.SetPlotOptions(new PlotOptions
{
Line = new PlotOptionsLine
{
DataLabels = new PlotOptionsLineDataLabels
{
Enabled = true
},
EnableMouseTracking = false
}
})
//load y values
.SetSeries(new[]
{
new Series {Name = "Patient",
Data = new Data(new object[] {ySeries})},
});
我的观点:
@{
ViewBag.Title = "IOPLeftChart";
}
<h2>IOPLeftChart</h2>
@model DotNet.Highcharts.Highcharts
<p> My Chart </p>
@(Model)
然而,当我运行应用程序时,它只显示一行,它应该显示一个3点的行。如下: